liveBook · Manning

Interquartile range

As explained in D3.js in Action, Third Edition

The interquartile range is the interval between the first and third quartiles containing the middle half of an ordered dataset.

The interquartile range (IQR) is the span from the first quartile (25th percentile) to the third quartile (75th percentile). It marks the middle 50% of a dataset, making it useful for showing where typical values concentrate without needing to show every data point. section 6.4

In a box plot, the rectangle encodes the IQR and a line crossing it marks the median. Whiskers extend from the minimum to the first quartile and from the third quartile to the maximum; points outside whiskers can be shown as outliers. This compact view emphasizes quartiles and the median, though it can be less immediately familiar than a histogram. section 6.4

To calculate and draw an interquartile range with D3:

  • Find the dataset values to summarize, along with its minimum and maximum when building a box plot. section 6.4
  • Use a quantile scale to calculate quartiles and the median. section 6.4
  • Map the first- and third-quartile positions to SVG coordinates, then draw the box or range marker at those positions. section 6.4

The IQR can also annotate a violin plot. A violin shows the full distribution as a mirrored, smoothed shape: it widens where bins contain more values and narrows where they contain fewer. Adding a line from the first to the third quartile preserves a compact summary of the middle half, while a dot can show the mean or median. section 6.5 section 6.6

Salary distributions by role

For salary data grouped by analyst, developer, designer, scientist, and leadership roles, first isolate each role’s salaries, calculate its mean, bins, and quartiles, then draw a violin. A line spanning the first and third quartiles highlights the role’s middle salary range; a dot marks its average salary. section 6.5

Figure 6.17 Violin plots of the salary distribution of the five leading data visualization roles. Each plot is combined with a gray line extending from the first to the third quartile and a white dot positioned at the mean value.
figure

Compare the gray first-to-third-quartile line with the surrounding violin shape and the white mean marker for each role. section 6.5

How D3.js in Action, Third Edition covers it

How deep it goes
Defines the first-to-third-quartile span and implements it through quantile scales and SVG positions.
Examples
Uses US salary distributions across five data-visualization roles, with IQR lines and mean dots on violin plots.
What it assumes
Assumes a dataset of numeric values and introduces quartile calculation with a quantile scale.
What you can do after
Build IQR markers in D3 box plots and violin plots from calculated quartile positions.
How it connects
Connects quartiles, median, mean, box plots, violin plots, histograms, bins, and quantile scales.

Also explained in

Compare how 7 books explain interquartile range →

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.