#Bar chart with 95% confidence interval
#First you compute a summary data set (mean, n, sd, se, ci per group)
#Second, then you plot from the summary data

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:Hmisc':
##
## src, summarize
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
# Calculates mean, sd, se and IC
my_sum <- dabestdat %>%
group_by(x) %>%
summarise(
n=n(),
mean=mean(y),
sd=sd(y)
) %>%
mutate( se=sd/sqrt(n)) %>%
mutate( ic=se * qt((1-0.05)/2 + .5, n-1))
## `summarise()` ungrouping output (override with `.groups` argument)
# Confidence Interval
ggplot(my_sum) +
geom_bar( aes(x=x, y=mean), stat="identity", fill="lightblue", alpha=0.8) + #alpha=transparency
geom_errorbar( aes(x=x, ymin=mean-ic, ymax=mean+ic), width=0.2, colour="black",
alpha=0.9, size=0.5) + #size=line thickness
ylab("Mean Dependent Variable Value") +
xlab("Intervention group") +
ylim(0,70) +
ggtitle("Dependent variable, 95% CI") +
theme_bw()