My dataframe (df) looks like this:
df
me SD class
3.11 4.08 A
2.09 3.50 B
1.75 2.72 C
0.34 0.85 D
Where me is the mean and SD is the standard deviation. I want to create a barplot of these mean values for each class and add the standard deviation on top of those bars:
To plot the bars:
ggplot(data=df) +
geom_bar(aes(x=class,y= me),
stat="identity",position="dodge")+
ylab("mean")+
xlab("class")+
theme(
text = element_text(size=20, colour="black"),
axis.text.x = element_text(angle=90, vjust=1, colour="black"),
axis.text.y = element_text(colour="black")) +
scale_y_continuous(breaks = round(seq(-2, 5, by = 0.5),1))
This works fine.
Now add the error-bar:
ggplot(data=df3) +
geom_bar(aes(x=class,y= me),
stat="identity",position="dodge")+
ylab("mean")+
xlab("class")+
theme(
text = element_text(size=20, colour="black"),
axis.text.x = element_text(angle=90, vjust=1, colour="black"),
axis.text.y = element_text(colour="black"))+
scale_y_continuous(breaks = round(seq(-2, 5, by = 0.5),1))+
geom_errorbar(aes(ymax = me + SD, ymin= me - SD),
position=position_dodge(0.9))
I got this error:
Error in data.frame(list(ymin = c(-1.96681604736652, -1.40293149619775, :
arguments imply differing number of rows: 28, 102

