Motion Chart

stats
dataviz
Author

Andy Grogan-Kaylor

Published

October 10, 2026

Using Observable JavaScript in Quarto, I have worked to build an example motion chart of the World Bank Data similar to those in this example.

Setup

Show the code
mydata = FileAttachment("WorldBankData.csv").csv({ typed: true })
Show the code
import {Scrubber} from "@mbostock/scrubber"

Motion Chart of Life Expectancy by GDP from World Bank Data

Show the code
viewof YEAR = Scrubber(d3.range(2000, 2020), {delay: 1000})
Show the code
Plot.plot({
  grid: true,
  color: {legend: false},
  symbol: {legend: true},
  x: { type: "log" },
  marks: [
    Plot.dot(mydata.filter(mydata=> mydata.year === YEAR), 
      {x: "GDP", 
      y: "life_expectancy", 
      fill: "region", 
      r: "population", 
      channels: {name: "country", year: "year"}, 
      tip: true}),
    Plot.linearRegressionY(mydata.filter(mydata=> mydata.year === YEAR), 
      { x: "GDP", y: "life_expectancy", stroke: "red" })

  ]
})