I read the boxplot docs, but didn't find the answer.
When using the default settings (boxplot(x.ts)
), what do the whiskers, boxes, midlines and outliers represent? Does it show quartiles or standard deviations?
Where is this documented?
I read the boxplot docs, but didn't find the answer.
When using the default settings (boxplot(x.ts)
), what do the whiskers, boxes, midlines and outliers represent? Does it show quartiles or standard deviations?
Where is this documented?
The documentation seems fairly clear to me, although it certainly helps to be familiar with how to read R
documentation and with boxplots more generally. Towards the bottom of the page it says:
See Also
boxplot.stats which does the computation...
So we can navigate there. It reads:
Details
The two ‘hinges’ are versions of the first and third quartile, i.e., close to
quantile
(x, c(1,3)/4)
. The hinges equal the quartiles for odd n (wheren <- length(x)
) and differ for even n. Whereas the quartiles only equal observations forn %% 4 == 1 (n = 1 mod 4)
, the hinges do so additionally forn %% 4 == 2 (n = 2 mod 4)
, and are in the middle of two observations otherwise.
And the Values
section includes:
stats
a vector of length 5, containing the extreme of the lower whisker, the lower ‘hinge’, the median, the upper ‘hinge’ and the extreme of the upper whisker.
Moreover, above that we see that the argument coef
is set to 1.5
by default (so that is what you would get unless you had changed the default for range
in the original boxplot
call). The coef
argument is documented:
coef
this determines how far the plot ‘whiskers’ extend out from the box. Ifcoef
is positive, the whiskers extend to the most extreme data point which is no more thancoef
times the length of the box away from the box. A value of zero causes the whiskers to extend to the data extremes (and no outliers be returned).
From these, we learn that the midline is the median of your data, with the upper and lower limits of the box being the third and first quartile1 (75th and 25th percentile) respectively. By default, the whiskers will extend up to 1.5 times the interquartile range from the top (bottom) of the box to the furthest datum within that distance. If there are any data beyond that distance, they are represented individually as points ('outliers').
To be explicit, they do not show standard deviations.
1. Note that determining the value for a quantile (e.g., the 25th percentile is potentially more complicated than people realize. There are at least nine different methods that have been discussed. For a nice overview, see @Glen_b's excellent answer here: Relation between Quintiles and the Arithmetic Mean.
This sums up the box plot and what each line represents.