R Ggplot2:如何将95%CI添加到因子百分比条形图中?

R Ggplot2:如何将95%CI添加到因子百分比条形图中?,r,ggplot2,errorbar,R,Ggplot2,Errorbar,我试图将95%的置信区间添加到频率条形图中。我曾尝试手动提取CI并将其输入到我的数据框函数中,但没有成功。有没有办法添加错误条,使它们看起来不像这样?我觉得这和我在原始绘图代码中的百分比函数有关 #Origin of the Value and Confidence Intervals yesHousingonly<-cows$Housing.Status[cows$Result == "yes"] prop.test(x = 7, n = 57, conf.level = 0.95)

我试图将95%的置信区间添加到频率条形图中。我曾尝试手动提取CI并将其输入到我的数据框函数中,但没有成功。有没有办法添加错误条,使它们看起来不像这样?我觉得这和我在原始绘图代码中的百分比函数有关

#Origin of the Value and Confidence Intervals
yesHousingonly<-cows$Housing.Status[cows$Result == "yes"]

prop.test(x = 7, n = 57, conf.level = 0.95)

data:  7 out of 57, null probability 0.5
X-squared = 30.947, df = 1, p-value = 2.651e-08
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
 0.05490086 0.24290721
sample estimates:
       p 
0.122807 

prop.test(x = 3, n =57, conf.level = 0.95)

data:  3 out of 57, null probability 0.5
X-squared = 43.86, df = 1, p-value = 3.528e-11
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
 0.0136917 0.1554719
sample estimates:
         p 
0.05263158 


#Data frame used to create ggplot
df5<-data.frame(yesHousingonly, upper=c(0.15, 0.24), lower=c(0.01, 0.05))

#GGplot of Percentage Prevalence of Cryptosporidium according to Housing Status
ggplotHousing<-ggplot(df5, aes(x = yesHousingonly, fill=yesHousingonly)) + geom_bar(aes(y = (..count..)/sum(..count..))) + theme_bw()

#Error Bar attempt
ggplotHousing 
+ ylim(0,0.8) + geom_errorbar(data = df5, mapping = aes(ymin= upper, ymax = lower))
#值的来源和置信区间

仅限yesHousingonly您能否向我们提供
yesHousingonly
对象中包含的数据?这将使我们能够高效地回答您的问题。您能否向我们提供
yesHousingonly
对象中包含的数据?这将使我们能够有效地回答你的问题。