I would like to put perpendicular lines at the ends of the whiskers like the boxplot
function automatically gives.
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).
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).
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.
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.
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')
The help for stat_boxplot
(?stat_boxplot
) detail the various values computed and saved in a data.frame
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With