A box-and-whisker plot, or boxplot, is a compact view of a numeric distribution. The box marks the interquartile range (IQR): values from the 25th to the 75th percentile, or the middle 50% of the data. A horizontal line inside the box marks the median. Whiskers extend beyond the box, and points beyond them are treated as outliers. section 14.5.1
Use boxplots when the analytical question is about how a distribution differs across groups. They make dispersion, medians, and unusual values visible without reducing a group to one average. Adding a mean point can be useful when the comparison or statistical test concerns group means rather than medians. section 4.5.2 section 7.4.1
A practical ggplot2 workflow is:
- Choose a categorical grouping variable for the x-axis and a numeric measure for the y-axis. section 14.5.1
- Add geom_boxplot() to draw one distribution for each group. section 4.5.2
- Optionally use stat_summary(fun = mean, geom = "point") to overlay each group mean. section 7.4.1
- Reshape paired measures from wide to long form with pivot_longer() before plotting them as groups. section 7.4.1
Comparing NBA draft outcomes
Career win shares can be plotted by college attendance and place of birth, or by draft year, to reveal that groups and draft classes do not share the same distribution. Summary statistics alongside the chart provide the minimum, quartiles, mean, median, and maximum needed to interpret the displayed spread. section 2.5.3
Spotting outliers before modeling
For player deflections, a boxplot isolates observations beyond the whiskers more directly than a scatterplot or histogram. After winsorizing values above 17.8, the revised boxplot shows no points beyond its whiskers. section 5.4.1
p3 <- ggplot(nba_stats, aes(x = o_pts_cat, y = z_wins, fill = o_pts_cat)) +
geom_boxplot(notch = TRUE, alpha = 0.5) +
labs(title = "Points Allowed vs. Wins",
subtitle = "2008-17",
x = "Standardized Points Allowed Category",
y = "Standardized Regular Season Wins") +
stat_summary(fun = mean, geom = "point",
shape = 20, size = 8, color = "white", fill = "white") +
theme(legend.position = "bottom") +
scale_fill_discrete(name = "Points\nAllowed\nZ-Score",
labels = c("< -1", "-1 to 0", "0 to 1","> 1")) +
theme(plot.title = element_text(face = "bold"))
This listing builds a grouped, notched boxplot of standardized wins by standardized points-allowed category, with fill colors and a mean marker. section 14.5.1





