liveBook · Manning

Median

As explained in D3.js in Action, Third Edition

The median is the middle value of an ordered dataset, or the midpoint between the two middle values when the dataset has an even size.

The median marks the second quartile, or 50th percentile: the threshold separating a dataset’s lower and higher halves. In a box plot, a perpendicular line makes this central value visible. section 6.4 section 6.4.1

Use the median when building distribution visualizations:

  • Calculate it directly with d3.median(), passing an array of values such as salary data. section 6.4.1
  • Calculate it alongside the first and third quartiles to describe the center and spread of a distribution. section 6.4
  • Represent it with an SVG line positioned between the lower and higher halves of the dataset. section 6.4.4

Comparing salary distributions

Separate the survey salaries into women’s and men’s arrays, calculate each median and quartile set, and place a median line inside each box plot. The resulting visualization compares the central salary values as well as the distributions’ ranges. section 6.4.1 section 6.4.4

d3.median(femalesSalaries);

Inspect the direct D3 expression for calculating a dataset’s median. section 6.4.1

How D3.js in Action, Third Edition covers it

How deep it goes
Defines the median as the 50th percentile and demonstrates D3 calculation and SVG placement without deriving the statistic.
Examples
Uses women’s and men’s salary arrays from a data-visualization survey and compares their medians in box plots.
What it assumes
Assumes familiarity with datasets and D3 arrays while introducing quartiles, quantile scales, and box-plot structure.
What you can do after
Builds a median calculation and visualizes it with D3 and SVG box-plot elements.
How it connects
Connects the median to quartiles, box plots, quantile scales, SVG, and distribution visualization.

Also explained in

Compare how 7 books explain median →

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.