Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put whisker ends on boxplot

Tags:

r

ggplot2

boxplot

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

like image 340
user1762299 Avatar asked Oct 20 '12 23:10

user1762299


People also ask

Can we customize the whiskers in a boxplot?

However, boxplot() can only set cap values of whiskers as the values of percentiles. e.g. Given my distribution is not a normal distribution, then the 95th/5th percentiles will not be the (mean+2std)/(mean-2std).

Where do the whiskers end on a box plot?

At the ends of the box, you” find the first quartile (the 25% mark) and the third quartile (the 75% mark). The far left of the chart (at the end of the left “whisker”) is the minimum (the smallest number in the set) and the far right is the maximum (the largest number in the set).

How do you change boxplot whiskers?

4, you can say: boxplots = ax. boxplot(myData, whis=[5, 95]) to set the whiskers at the 5th and 95th percentiles. Similarly, you'll be able to say boxplots = ax. boxplot(myData, whis=[0, 100]) to set the whiskers at the min and max.

How far out do the whiskers extend in a boxplot?

Each whisker extends to the furthest data point in each wing that is within 1.5 times the IQR. Any data point further than that distance is considered an outlier, and is marked with a dot.


1 Answers

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

like image 102
mnel Avatar answered Nov 09 '22 15:11

mnel