27 Box Plots
A box plot (or box-and-whisker plot) summarizes a numeric variable’s distribution using five statistics: the minimum, first quartile (Q1), median, third quartile (Q3), and maximum. The box spans Q1 to Q3 (the interquartile range), a line marks the median, and whiskers extend to the smallest and largest values that aren’t flagged as outliers — any point beyond the whiskers is plotted individually as a potential outlier.
Box plots are especially good at two things a histogram doesn’t do as well: comparing the spread of several groups side by side, and flagging outliers explicitly.
27.1 Creating a Box Plot
In R, the base boxplot() function builds a box plot directly from a numeric vector or a formula.
The box captures where the middle half of farms fall, the line inside it marks the median yield, and the two isolated points below and above the whiskers flag farms worth a closer look — an unusually poor or unusually strong season.
27.2 Grouped Box Plot
A grouped box plot places one box per category side by side, making it easy to compare how a variable’s distribution — not just its average — differs across groups.
Canal-irrigated farms show both a higher median yield and a tighter spread than rainfed farms — exactly the kind of pattern a box plot surfaces at a glance that a table of averages alone would hide.
27.3 Horizontal Notched Box Plot
Two refinements are often layered onto a box plot:
-
Horizontal orientation (
horizontal = TRUE) reads more naturally when category labels are long. -
Notches (
notch = TRUE) narrow the box around the median to show an approximate confidence interval — when two groups’ notches don’t overlap, their medians are likely genuinely different, not just different by chance.
Summary
| Concept | Description |
|---|---|
| Box Plots | |
| Box Plot | Summarizes a numeric variable's distribution (min, Q1, median, Q3, max) and flags outliers, e.g., yield across farms |
| Grouped Box Plot | Places one box per category side by side to compare distributions across groups, e.g., yield by irrigation type |
| Horizontal Notched Box Plot | Reorients the boxes horizontally and adds notches around the median to indicate whether group medians likely differ |