matteo
matteo

Reputation: 4873

Change boxplot limits in R

I'm trying to change the upper and lower limit of a boxplot.

I need to to change from 5% to 10% (lower) and from 95% to 90% (upper).

Moreover, I have to use the standard boxplot function (no ggplot unfortunately).

I tried to calculate the quantiles (quantile function) but I don't know how the boxplot function can understand the new values.

Some ideas?

Upvotes: 2

Views: 5874

Answers (1)

Barranka
Barranka

Reputation: 21047

A boxplot has the following structure:

Boxplot explanation

As I understand your question, you need the upper hinge to reflect the occurrences up to the 90% percentile, and the lower inge to reflect the occurrences above 10% percentile.

As far as I know, you can't change the size of the box (which will always go from the 25% percentile to the 75% percentile (1st and 3rd quartile). What you can manipulate is the length of the whiskers, and for that, you can use the range argument of the boxplot() function (see here for the documentation). But you can't set the length of the whisker in terms of the quantiles of the values; you can only set the max length of the whisker in terms of the IQR (Interquartile range: IQR = abs(quantile(x, 0.75) - quantile(x, 0.25))). By default, the max length of the whisker will be 1.5 times the IQR but you can change that:

boxplot(x, range=0.5) # This will make the max length of the whisker
                      # to be 0.5 * IQR

I don't know if there's a way to make the range of the whisker to be explicitely a quantile (at least with the standard boxplot() function)

Upvotes: 7

Related Questions