We all love robust measures like medians and interquartile ranges, but lets face it, in many fields, boxplots almost never show up in published articles, while means and sta
Coming a little late to the game, but this solution might be useful for future users. It uses the diamond
data.frame loaded with R and takes advantage of stat_summary
along with two (super short) custom functions.
require(ggplot2)
# create functions to get the lower and upper bounds of the error bars
stderr <- function(x){sqrt(var(x,na.rm=TRUE)/length(na.omit(x)))}
lowsd <- function(x){return(mean(x)-stderr(x))}
highsd <- function(x){return(mean(x)+stderr(x))}
# create a ggplot
ggplot(diamonds,aes(cut,price,fill=color))+
# first layer is barplot with means
stat_summary(fun.y=mean, geom="bar", position="dodge", colour='white')+
# second layer overlays the error bars using the functions defined above
stat_summary(fun.y=mean, fun.ymin=lowsd, fun.ymax=highsd, geom="errorbar", position="dodge",color = 'black', size=.5)