具有均值和标准差的 R 手动箱线图 (ggplot2)

R manual boxplot with means and standard deviations (ggplot2)

我有两组平均分数和标准差,它们代表我们对平均估计的信心程度。注意:我没有原始分数,只是表示从模型输出的估计值和从模型输出的估计值的 SD,围绕该平均值。

我有一个大约 20 个特征集,我想比较每个特征的 2 个组的平均 +/- 标准差。它基本上看起来像这样:

ggplot() 似乎适用于具有原始数据的数据,它计算每个特征数组的均值和标准差。 boxplot() 的工作原理类似。

谁能帮我想出一种方法来以这种方式可视化我的结果?

在这种情况下,我认为您不需要箱线图。您可以使用 ggplot2 包中的 geom_errorbar 之类的东西。请提供数据或示例数据以使您的问题可重现。

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")