R manual boxplot with means and standard deviations (ggplot2)

蓝咒 提交于 2019-12-04 18:51:14

I don't think you want a boxplot in this case. You could use something like geom_errorbar from the ggplot2 package. Please provide data or sample data to make your question reproducible.

df <- data.frame(means = rnorm(20, 5, 2),
                   sds = rnorm(20),
                 feats = c(paste0("Feature ", letters[1:10])),
                 group = rep(c("group 1", "group 2"), each = 2))
head(df)
#      means        sds     feats   group
# 1 7.298374 -1.1545645 Feature a group 1
# 2 6.124870 -0.0694843 Feature b group 1
# 3 3.855704  0.3802556 Feature c group 2
# 4 6.357659  2.2822757 Feature d group 2
# 5 3.572474 -0.9488784 Feature e group 1
# 6 3.526351  2.5956482 Feature f group 1

library(ggplot2)
ggplot(df, aes(x = feats, color = group)) +
  geom_errorbar(aes(ymax = means + sds, ymin = means - sds),
                position = "dodge")

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!