手动将置信区间添加到条形图

Manually add confidence intervals to barplots

我必须遵循具有置信区间 "ci_min" 和 ci_max" 的数据框,对于物种 "x" 和 "y" 的每个平均值。如何手动添加置信区间条形图?

data <- data.frame("sp" = c("x","y"), count = c(-4.011, 2.45), "ci_min" = c(-4.2,1.68), "ci_max" = c(-4.01, 3.28))

library(ggplot2)
ggplot(data, aes(x = sp, y = counts, fill = sp)) +
    stat_summary(geom="bar", fun.y=mean, position = "dodge") 

您可以通过在主 ggplot2 调用中指定 yminymax 来使用 geom_errobar 添加误差线。

ggplot(data, aes(sp, count, ymin = ci_min, ymax = ci_max, fill = sp)) + 
    geom_bar(stat = "identity") +
    geom_errorbar()