如何生成关于包含两个数据集barplot错误吧?(How to you generate error

2019-10-23 10:49发布

我已经产生如下所示的barplot,我目前试图添加误差线。 我用数据的两列,以产生沿x轴所示的条。 是否有可能使用标准devation /标准误差值增加误差条到每个在x轴上,如果是这样的两组数据,我该怎么办呢? 我已经添加了我的一些原始数据和代码,帮助更有意义,并已尝试使用箭头功能,以添加误差线,但我没能找出两到两个吸引,并没有引起这样做酒吧。

在此先感谢您的帮助。

Species         Not attracted   Number attracted
Atlantic cod       92           0
Haddock             0           0
Whiting             0           0
Haddock             0           0
Whiting             0           0
Atlantic cod        2           0
Haddock             0           0
Whiting             0           1

meanMNAtt <- tapply(MaxN$Number.attracted, list(MaxN$Species), mean)
sdMNAtt<- tapply(MaxN$Number.attracted, list(MaxN$Species), sd)
meanMNnotAtt <- tapply(MaxN$Not.attracted, list(MaxN$Species), mean)
sdNA <- tapply(MaxN$Not.attracted, list(MaxN$Species), sd)

MN_mean <- matrix(c(0.02083333, 0.89583333, 1.41666667, 2.770833, 1.083333,     0.125000), 2, 3, byrow = TRUE, dimnames = list(c("Attracted", "Not Attracted"), c("Atlantic cod", "Haddock", "Whiting")))

MN_sd <- matrix(c(0.1443376, 1.9267389, 2.5751127, 13.3372612, 2.8346889, 0.3927535), 2, 3, byrow = TRUE, dimnames = list(c("SD_Att", "SD_NAtt"), c("Atlantic cod", "Haddock", "Whiting")))

SDPlot <- barplot(MN_mean, beside=TRUE, ylim=c(0, 5), xlab="Species", ylab="Attraction at MaxN", axes=TRUE, las=1, col = c("Black", "Gray60"))

Answer 1:

你的阴谋后,添加它使用segments

segments(x0=SDPlot, y0=MN_mean-MN_sd, x1=SDPlot, y1=MN_mean+MN_sd, lwd=2)

如果你也想的水平端部:

segments(x0=SDPlot-0.1, y0=MN_mean-MN_sd, x1=SDPlot+0.1, y1=MN_mean-MN_sd, lwd=2)
segments(x0=SDPlot-0.1, y0=MN_mean+MN_sd, x1=SDPlot+0.1, y1=MN_mean+MN_sd, lwd=2)


文章来源: How to you generate error bars on barplot containing two data sets?
标签: r plot bar-chart