R – Put whisker ends on boxplot

boxplotggplot2r

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

Best Answer

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

Related Topic