Я пытаюсь добавить 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))