Put whisker ends on boxplot

user1762299 picture user1762299 · Oct 21, 2012 · Viewed 44.4k times · Source

I would like to put perpendicular lines at the ends of the whiskers like the boxplot function automatically gives.

Answer

mnel picture mnel · Oct 22, 2012

As hinted but not implemented by @Roland, you can use stat_boxplot to implement this. The trick calling _boxplot twice and is to set the geom to errorbar for one of the calls.

Note that as R uses a pen and paper approach it is advisable to implement the error bars first the draw the traditional boxplot over the top.

Using @Roland's dummy data df

ggplot(df, aes(x=cond, y = value))  + 
 stat_boxplot(geom ='errorbar') + 
 geom_boxplot() # shorthand for  stat_boxplot(geom='boxplot')

enter image description here

The help for stat_boxplot (?stat_boxplot) detail the various values computed and saved in a data.frame