I'm trying to create a barplot
with confidence interval error bars using ggplot
. Essentially, I have a variable, Q1
, with 7 answer options, and I want to plot the percent of respondents for each option, as a factor of two groups (One and Two) - the percent of subjects in each group that selected each of the 7 answer option.
I've tried adding y= count
, y=prop
or y=..prop..
to aes
in ggplot
, but it neither seem to work. Any suggestions are appreciated.
df5 <- filter(df, Q1!="-99",df$Group=="One"|df$Group=="Two")
ggplot(data = df5, aes(x = Q1)) +
stat_summary(fun.y = mean, geom = "bar") +
stat_summary(fun.data = mean_cl_boot, geom = "errorbar", fun.args = list(mult = 1)) +
geom_bar(aes(label= scales::percent(..prop..),
y= ..prop..,fill = df5$Group), position = "dodge")
Error: stat_summary requires the following missing aesthetics: y.
I'm essentially trying to get something that looks like this, with the error bars representing confidence intervals.