liveBook · Manning

Mean

As explained in D3.js in Action, Third Edition

The mean is the arithmetic average obtained by summing numeric observations and dividing by their count.

The mean is the arithmetic average: add numeric observations and divide by their count. In distribution charts, it marks a typical value alongside the broader shape of the data. section 6.5

A mean becomes useful when comparing groups. A violin plot can show an entire distribution while placing a dot at each group’s mean, making average values easy to compare without hiding variation. section 6.5 section 6.0

Calculate and use the mean in a D3 visualization:

  • Isolate the numeric observations for a group, such as salaries belonging to one role. section 6.5
  • Call d3.mean(values) to calculate the group’s average, then store the result with the group’s data. section 6.5
  • Use the result as a visual position, such as a dot on a salary axis, and compare it with quartiles or the median. section 6.5

Average salary by role

For each role, filter the dataset to matching records, map the records to salary values, and calculate the average with role["mean"] = d3.mean(role.salaries). Sorting roles by a.mean - b.mean then orders them from the lowest to highest mean 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

Inspect the violin plots to see mean values represented as dots beside interquartile ranges and complete distributions. section 6.5

How D3.js in Action, Third Edition covers it

How deep it goes
Explains group extraction, d3.mean calculation, sorting, and visual placement while stopping short of deeper statistical interpretation.
Examples
Demonstrates average salaries for analysts, developers, designers, scientists, and leadership roles in violin plots.
What it assumes
Assumes basic JavaScript arrays and D3 data transformations while teaching the visualization use of an average value.
What you can do after
Apply the mean via d3.mean to calculate group averages and place them in D3 distribution visualizations.
How it connects
Connects the mean to distributions, violin plots, quartiles, medians, bins, and D3 scales.

Also explained in

Compare how 29 books explain mean →

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.