Boxplot

What is a Boxplot?

A boxplot (also called a box-and-whisker plot) summarises the location and spread of a numeric variable. The box shows the median and the central part of the data; whiskers and separately drawn points show the tails. In R's default boxplot, the whisker ends need not be the minimum and maximum of the sample.

Comic: someone uses a boxplot comparing time spent together to argue that a relationship is statistically significant.
Comic by Randall Munroe (xkcd).

Examine the following items to learn more about the location and spread of the sample data:

The Median is represented by the line in the box. The median is a common measure of the location of the data. Half of the observations are less than or equal to the value, the other half of the observations are greater than or equal to the value.

The box covers approximately the middle 50% of the data. The interquartile range (IQR) is Q3 minus Q1. R uses Tukey's hinges as the box edges; these approximate Q1 and Q3 but can differ from the values returned by quantile(), especially in small samples. In the rules below, IQR means the box length: upper hinge minus lower hinge.

The whiskers extend to the smallest and largest observed values within 1.5 × IQR of the corresponding box edge. The limits are the lower hinge minus 1.5 × IQR and the upper hinge plus 1.5 × IQR. A whisker ends at an observed value, not necessarily at the limit itself. These are the defaults of boxplot() (range = 1.5).

Potential outliers beyond these limits are drawn individually. This flags observations for investigation; it does not establish that they are data errors or should be removed. Several observations with the same value may overlap in the plot.

The notch, when requested, extends from the median by ±1.58 × IQR / √n, where n is the group sample size. Non-overlapping notches provide approximate evidence that two population medians differ at roughly the 5% level. This comparison relies on an approximation, and is less reliable with small samples; the notches are not guaranteed 95% confidence intervals for individual medians. Overlapping notches do not establish equal medians.

These conventions are described in the R documentation for boxplot() and boxplot.stats().

Annotated R boxplot showing hinges, median, observed whisker ends, the 1.5 times IQR limits, a potential outlier and approximate notches.
R’s default whisker rule and optional notches, illustrated with generated example data. Dashed limits determine which observations are drawn separately; whiskers stop at observed values.

Example with mtcars:

Boxplot of MPG by Car Cylinders

boxplot(mpg~cyl,data=mtcars, main="Car Milage Data",
        xlab="Number of Cylinders", ylab="Miles Per Gallon")

Notched and colored Boxplot of MPG by Car Cylinders

boxplot(mpg~cyl,data=mtcars, main="Car Milage Data", notch=TRUE,
        col=(c("steelblue","darkgreen", "darkred")),
        xlab="Number of Cylinders", ylab="Miles Per Gallon")
Mtcars mpg by 4, 6 and 8 cylinders, first as plain boxplots and then with coloured notches. Four-cylinder cars have the highest median mpg and eight-cylinder cars the lowest.
Simple Boxplot and notched and colored Boxplot.

In the eight-cylinder group, the lower whisker is at 13.3 mpg, while two observations at 10.4 mpg are flagged by the 1.5 × IQR rule. Their symbols overlap, so only one circle is visible. For the six-cylinder group, R warns that some notches extend outside the hinges: there are only seven observations, and the notch interval extends beyond the box. Interpret these small-sample comparisons cautiously.

Updated: