liveBook · Manning

Scatter plot

As explained in D3.js in Action, Third Edition

A scatterplot displays a collection of data points positioned along coordinate axes to show relationships between variables.

A scatter plot places data points on coordinate axes to visualize relationships between variables. In D3, it emerges from assembling reusable building blocks: axes, scales, bound data, and circles. section 4.2

Plotting temperature data

Bind temperature records to circles, map each date through an x-scale, map each average temperature through a y-scale, and give every point a consistent radius and color. section 4.2

const aubergine = "#75485E";
innerChart
  .selectAll("circle")  #1
  .data(data)          
  .join("circle")      
    .attr("r", 4)
    .attr("cx", d => xScale(d.date))        #2
    .attr("cy", d => yScale(d.avg_temp_F)) 
    .attr("fill", aubergine);

This implementation shows the essential pattern: join data to circles, then derive horizontal and vertical positions from scale accessors. section 4.2

Extend a scatter plot by encoding more variables and responding to data changes:

  • Represent a third variable with circle area and another with color. section 7.4
  • Filter the dataset and animate circles entering or exiting the visualization. section 7.4
  • Let D3 control the visualization’s portion of a frontend application DOM. section 8.5

How D3.js in Action, Third Edition covers it

How deep it goes
Explains construction, encodings, filtering, animation, and DOM integration without developing statistical interpretation.
Examples
Uses temperature records, cetacean populations, framework retention and user counts, and animated regional filters.
What it assumes
Assumes familiarity with JavaScript objects, axes, scales, and positioning bound data, while developing chart construction incrementally.
What you can do after
Build it from scratch with D3 using axes, scales, circles, data joins, additional encodings, and animated filtering.
How it connects
Connects axes, scales, data binding, SVG circles, filtering, enter and exit selections, and DOM control.

Also explained in

Compare how 8 books explain scatter 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.