R语言学习笔记9-绘制barplot

一、条形图

barplot基本语法:

1
barplot(H,xlab,ylab,main, names.arg,col,horiz=FALSE,density,las)

H - 用于创建柱状图的矢量或矩阵
xlab - X轴标签
ylab - Y轴标签
main - 柱状图的标题
names.arg - 每个柱的名称
col - 柱的颜色
horiz - 默认为FALSE,即竖直方向
density - 条纹密度
las - 坐标轴字体方向,las=1为水平方向,las=2为垂直方向

1
2
data <- c(3,5,7) # 创建数据
barplot(data,main="Expression",ylab="gene",xlab="relative expresstion level",names.arg=c("gene1","gene2","gene3"),horiz=TRUE,col="green",border="red",density=c(5,10,15))

二、堆叠图

1
2
3
4
data <- matrix(c(2,9,3,11,9,4,8,7,3,12,5,2,8,10,11),nrow=3,ncol=5,byrow=TRUE) # 创建3行5列的向量
barplot(data,col=c("green","red","blue"),names.arg=c("J","F","M","A","S")) # 堆叠图
kinds <- c("A","B","C")
legend("topleft",kinds,cex=0.8,fill=c("green","red","blue")) # 添加图例

三、分组图

1
2
3
barplot(data,col=c("green","red","blue"),names.arg=c("J","F","M","A","S"),beside=TRUE) # 添加beside=TRUE即为分组图
kinds <- c("D","E","F")
legend("topleft",kinds,cex=0.8,fill=c("green","red","blue")) # 添加图例

  • 本文作者:括囊无誉
  • 本文链接: R/R_learn_9/
  • 版权声明: 本博客所有文章均为原创作品,转载请注明出处!
------ 本文结束 ------
坚持原创文章分享,您的支持将鼓励我继续创作!