The "range" equivalent in boxplot for ggplot2

I'm trying to get a ggplot2 geom_boxplot mustache to cover emissions. Emissions de facto will not be displayed as dots, as they are covered by boxplot.

If I used the standard "boxplot", I would use:

boxplot(x, range=n) 

where n will be a large number, so instead of displaying outliers, boxes with squares expand to cover outliers.

How can this be done with ggplot2? I tried:

 ggplot(myDF, aes(x=x, y=y)) + geom_boxplot(range = 5) 

Note. I don't want to throw emissions using something like:

 geom_boxplot(outlier.shape = NA) 
+4
source share
2 answers

The only way I know is to calculate the field values ​​myself as follows:

 library(plyr) xx <- ddply(mtcars,.(cyl), transform, ymin = min(mpg), ymax = max(mpg), middle = median(mpg), lower = quantile(mpg,0.25), upper = quantile(mpg,0.75)) ggplot(data = xx,aes(x = factor(cyl))) + geom_boxplot(aes(ymin = ymin,ymax = ymax,middle = middle,upper = upper,lower= lower), stat = 'identity') 

There are a few ddply call ddply , but you should be able to ignore them safely.

+2
source

I believe this question is still relevant, because this page is at the top of Google’s search query about this issue. So:

An easier way to handle emissions is (at least in the latest ggplot, as of April 04, 2016) - use "coef":

 ... + geom_boxplot(coef = 5) 

From the manual (? Geom_boxplot output copy-paste below):

coef mustache length as a multiplicity of IQR. Default 1.5

More details

The upper whisker extends from the hinge to the highest value, which is within 1.5 * IQR of the hinge, where IQR is the interquartile range, or the distance between the first and third quartiles. The bobbin thread extends from the hinge to the lowest value within the 1.5 * IQR loop. Data outside the mustache is emissions and (as indicated by Tuki).

In the notch notch, the notches expand by 1.58 * IQR / sqrt (n). This yields approximately 95 See McGill et al. (1978) for more details.

+4
source

Source: https://habr.com/ru/post/1500324/


All Articles