我想为this link制作一个类似的图表。但是,我想为每个均值显示误差条,我不知道如何在R中执行此操作。 我想将MeansG1和MeansG2绘制为单独的图。我的数据:
data<-structure(list(MeansG1=c(10.780877,8.675726,10.398065,11.617315,12.231693,8.292337,8.093416,10.744478,10.531539,11.459219,12.316292,11.272801),
STEG1=c(0.2578710,0.2569172,0.2502743,0.2558724,0.2523819,0.2427068,0.2507437,0.2475850,0.2421691,0.2365641,0.2350861,0.2312222),
MeansG2=c(11.780877,9.675726,11.398065,12.617315,13.231693,12.292337,12.093416,12.744478,12.531539,11.459219,12.316292,12.272801),
STEG2=c(0.2578710,0.2569172,0.2502743,0.2558724,0.2523819,0.2427068,0.2507437,0.2475850,0.2421691,0.2365641,0.2350861,0.2312222)),
.Names = c("MeansG1", "STEG1", "MeansG2", "STEG2"), row.names=1:12,class = "data.frame")
感谢。
答案 0 :(得分:0)
我更喜欢polygon()
来完成这项任务。下面是使用您的数据的示例。我希望它有所帮助,让我知道是否需要解释。
# get the data ready
g1 <- data.frame(mean = data$MeansG1,
up = data$MeansG1 + data$STEG1,
down = data$MeansG1 - data$STEG1)
g2 <- data.frame(mean = data$MeansG2,
up = data$MeansG2 + data$STEG2,
down = data$MeansG2 - data$STEG2)
plotData <- list(g1, g2)
# setup the plotting region
par(mfcol = c(2, 1))
### make the plots
for(i in plotData){
dd <- i
plot(dd$mean, type = "n", ylim = range(dd))
xvals <- 1:dim(dd)[1]
polygon(c(xvals, rev(xvals)), c(dd$up, rev(dd$down)), col = "#ff000050", border = NA)
lines(dd$mean, col = "red")
}