plot() 多种图形
hist()频率直方图
boxplot()箱式图
stripchart()点图
barplot()柱状图
dotplot()点图
piechart()饼图
matplot()数学图形
lines()添加线
curve()添加曲线
abline()添加给定斜率的线
points()添加点
segments()折线
arrows()箭头
axis()坐标轴
box()外框
title()标题
text()文字
#1.基础包
plot(iris[,1],iris[,3],col = iris[,5]) #iris为数据框,以iris第一列为横坐标,第三列为纵坐标,第五列有多少个不同的取值则有多少种颜色
text(6.5,4, labels = 'hello')#在(6.5,4)坐标处添加“hello”
dev.off() #关闭画板
#2.ggplot2 中坚力量,语法有个性
library(ggplot2)
ggplot(data = iris)+
geom_point(mapping = aes(x = Sepal.Length,
y = Petal.Length,
color = Species))#以iris数据框作点图,x=和y=分别表示行名和列名,Sepal.Length为数据框中的列名
属性 | 参数 |
---|---|
颜色 | color |
大小(单位mm) | size |
透明度 | alpha |
填充颜色(1-20均用不到fill函数)) | fill |
形状(数字编号见下图) | shape |
1.
ggplot(data=iris)+
geom_point(mapping=aes(x=Sepal.Length,y=Sepal.Length),size=2,alpha=0.5,shape=21)
ggplot(data=iris)+
geom_point(mapping=aes(x=Sepal.Length,y=Sepal.Length,color=Species))
ggplot(data=iris)+
geom_point(mapping=aes(x=Sepal.Length,y=Sepal.Length),color="red")
ggplot(data=iris)+
geom_point(mapping=aes(x=Sepal.Length,y=Sepal.Length,color=Species))+
scale_color_manual(values=c("blue","red","yellow"))
ggplot(data=iris)+
geom_point(mapping=aes(x=Sepal.Length,y=Sepal.Length,color=Species))+
facet_wrap(~Species)
dat = iris
dat$Group = sample(letters[1:5],150,replace = T)#sample表示取样,从abcde中取150个样(可重复取样)
ggplot(data = dat) +
geom_point(mapping = aes(x = Sepal.Length, y = Petal.Length)) +
facet_grid(Group ~ Species)
ggplot(data = iris,mapping = aes(x = Sepal.Length, y = Petal.Length))+
geom_smooth()+
geom_violin(aes(fill=species))+#小提琴图有颜色填充
geom_jitter(aes(shape=1))#点的形状
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut))#自动统计x出现的次数作为纵坐标
ggplot(data = diamonds) +
stat_count(mapping = aes(x = cut))#两种代码所作的图相同
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))#group=1表示cut中的所有组作为一个整体,百分比相加等于1
pdat.data.frame
rownames | group | gene | count |
---|---|---|---|
test1 | control | gene1 | 0.1 |
test2 | treat | gene2 | 0.2 |
library(ggplot2)
p = ggplot(pdat,aes(gene,count))+
geom_boxplot(aes(fill = group))+
theme_bw()
p
p + facet_wrap(~gene,scales = "free")
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。