I am trying to create a plot of the mean and sd (side by side) of a variable for two different groups in R to get something like this.
where blue bars are means and orange bars are SDs.
I use the ggplot2 package in R for this. If I use these codes separately
ggplot(data, aes(x=factor(grouping variable), y=my variable)) + stat_summary(fun.y="mean", geom="bar", col="blue")
ggplot(data, aes(x=factor(grouping variable), y=my variable)) + stat_summary(fun.y="sd", geom="bar", col="orange")
they function well but produce the mean and sd in two different graphs.
So I tried to combine them in one graph by using
stat = "summary", fun.y = "mean" and stat = "summary", fun.y = "sd"
and what I got
ggplot(data, aes(x=factor(grouping variable)) + geom_bar(aes(y=my variable), stat = "summary", fun.y = "mean", position="dodge",col="blue") + geom_bar(aes(y=my variable), stat = "summary", fun.y = "sd", position="dodge",col="orange")
and the following error has emerged
Error: unexpected symbol in:
"ggplot(data, aes(x=factor(grouping variable)) + geom_bar(aes(y=my variable), stat = "summary", fun.y = "mean", position="dodge",col="blue") + geom_bar(aes(y=my variable), stat = "summary", fun.y = "sd", positi ggplot"
Could you help to fix the error or maybe there is another way to do this?
Updated information: the sample of my data looks like enter image description here
I run the following code on these data to plot mean tTTO and sd tTTO for both interviewers:
ggplot(timeTTO, aes(x=interviewer, y=tTTO)) +
theme_light() +
labs(title = "Figure 3. Time taken to complete a single TTO task, by interviewer", x=NULL, y=NULL) +
theme(plot.title = element_text(face = "bold")) +
geom_bar(stat = "summary", fun.y = "mean",width=0.25, fill = "blue") +
geom_bar(stat = "summary", fun.y = "sd", width=0.25,fill = "orange")
and I got something like this where blue bars are the means and orange bars are SDs: enter image description here
Actually, I have tried with position="dodge" put it in both geom_bar() functions, it did not work