R学习笔记-可视化-带有置信区间的条形图

带有置信区间的条形图

(1)

library(gplots)
attach(airquality)
heights <- tapply(Temp,Month,mean)
lower <- tapply(Temp,Month,function(v) t.test(v)$conf.int[1])
upper <- tapply(Temp,Month,function(v) t.test(v)$conf.int[2])
barplot2(heights,plot.ci=TRUE,ci.l=lower,ci.u=upper,
           ylim=c(50,90),
           col=c("bisque1","cyan2","darkgoldenrod","darkorange1","darkolivegreen2"),
           xpd=FALSE)
           #space=0,柱子之间的间距=0

在这里插入图片描述

(2)

使用数据:data(np:55)
| 在这里插入图片描述| |

data<-read.csv("data.csv")
aa<-data[,1]
bb<-data[,2:6]
row.names(bb)<-aa
colnames(bb)<-c("<0.10","[0.10,0.20)","[0.20,0.30)","[0.30,0.70]",">0.70")
bb<-as.matrix(bb)
tem<-read.csv("loup.csv")
lower<-tem[1:5,]
upper<-tem[6:10,]
row.names(lower)<-aa
row.names(upper)<-aa
colnames(lower)<-c("<0.10","[0.10,0.20)","[0.20,0.30)","[0.30,0.70]",">0.70")
colnames(upper)<-c("<0.10","[0.10,0.20)","[0.20,0.30)","[0.30,0.70]",">0.70")
lower<-as.matrix(lower)
upper<-as.matrix(upper)
zz<-barplot2(bb,beside=T,plot.ci=TRUE, cex.names =0.8,ci.l=lower,ci.u=upper,xpd=FALSE,col = c("lightblue3", "indianred1", "darkolivegreen3","lightpink1", "mediumpurple1"), plot.grid = TRUE,border = "black")
box()
legend("topright", legend=rownames(bb), fill =c("lightblue3", "indianred1", "darkolivegreen3",                                     "lightpink1", "mediumpurple1"),text.col = "black")
mtext(side = 1, at = colMeans(zz), line = -2,text = paste("Mean", percent(colMeans(bb))), col = "red")

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值