【R作图】如何画带标准差的柱状图

画带标准差的柱状图,除了barplot之外,还需要用到Hmisc包中的errbar。

x=read.table("correlation_coefficient_inter-class")
y=read.table("correlation_coefficient_between-class")
inter=mean(x[,1])
between=mean(y[,1])
y_mean=cbind(inter,between)
mp=barplot(y_mean,ylim=c(0,1),
           col = c(rgb(216,179,101,maxColorValue=255),rgb(90,180,172,maxColorValue=255)),
           beside=TRUE,space =c(0.1,0.7),width=c(0.1,0.1))
library(Hmisc)
cl=rgb(140,81,10,maxColorValue=255)
errbar(mp,y_mean,y_mean +c(sd(x[,1]),sd(y[,1])), y_mean - c(sd(x[,1]),sd(y[,1])),
       cap=0.035,errbar.col=cl,col=cl,lwd=3,add=T)
p=wilcox.test(x[,1],y[,1])$p.value
mtext(paste("p=",p),col=1, font=2, cex= 1.5)

注:mp能指定位置,将errbar画在柱子上。

posted on 2012-12-25 11:02  香格里拉\(^o^)/  阅读(11972)  评论(0编辑  收藏  举报