liveBook · Manning

Box-and-whisker plot

As explained in D3.js in Action, Third Edition

A box plot is a statistical chart that summarizes a distribution using a box between the first and third quartiles, a median line, and whiskers extending toward the minimum and maximum values.

A box-and-whisker plot summarizes a distribution compactly. Its rectangle spans the first quartile to the third quartile, a line marks the median, and whiskers extend toward the minimum and maximum values. Outliers may appear as dots beyond the whiskers. section 6.4

Build a box plot in D3 by following this sequence:

  • Find the dataset’s minimum and maximum values. section 6.4
  • Use d3.scaleQuantile() to calculate the first quartile, median, and third quartile. section 6.4 section 6.6
  • Map values through a vertical scale, then append SVG rectangles and lines using the resulting positions. section 6.4 section 6.4.4
  • Set the rectangle height from the third-quartile position to the first-quartile position, accounting for the SVG y-axis direction. section 6.4.4

Comparing salary distributions

Place two box plots on one chart to compare salaries for women and men working in data visualization in the United States. Use a discrete horizontal scale for the categories and a continuous vertical scale for salaries. The vertical scale positions each minimum, quartile, median, and maximum; individual salary points can be overlaid as circles, with randomized horizontal positions to reduce overlap. section 6.4.2 section 6.4.4

Figure 6.14 A box plot is composed of a rectangle extending from the first to the third quartile, a line positioned at the median, and whiskers extending from the minimum value to the first quartile and from the third quartile to the maximum value.
figure

Use the annotated figure to identify the rectangle, median line, and two whisker segments that form the complete plot. section 6.4.4

How D3.js in Action, Third Edition covers it

How deep it goes
Explains statistical components and D3 construction through scales, SVG attributes, rectangles, median lines, and whiskers.
Examples
Uses United States data-visualization salaries, gender comparisons, overlaid salary circles, and configurable SVG box dimensions.
What it assumes
Requires dataset values and teaches quartile calculation, scale mapping, and SVG construction within a D3 visualization workflow.
What you can do after
Build it from scratch in D3 by calculating distribution statistics and drawing their positions with SVG elements.
How it connects
Connects distributions, histograms, quartiles, medians, violin plots, quantile scales, point scales, and SVG.

Also explained in

Compare how 6 books explain box-and-whisker plot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.