繁体   English   中英

手动为条形图添加置信区间

[英]Manually add confidence intervals to barplots

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

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的误差ggplot2

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

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM