Skip to content

Bubble Chart ​

Penguins by culmen length and depth, one dot per penguin, sized by body mass and colored by species. As with Plot's r scale, the radius is the square root of the mass from 0, so a dot's area tracks the mass. Its range is widened so the differences show. Legends for species and mass are implicit guides, turned on by the scale options of cm.plane.

js
// Two penguins without measurements are left out.
const penguins = (await d3.csv("/data/penguins.csv", d3.autoType)).filter((d) => !isNaN(d.culmen_length_mm));

const renderer = cm.svg({width: 640, height: 480});
const root = cm.flow().renderer(renderer);

root
  .data(penguins)
  .transform(cm.encode, {x: "culmen_length_mm", y: "culmen_depth_mm", r: "body_mass_g", fill: "species"})
  .transform(cm.plane, {
    x: {grid: true},
    y: {grid: true},
    fill: {legend: true},
    r: {range: [0, 10], legend: true},
  })
  .add(cm.circle, {fillOpacity: 0.5, stroke: "white", strokeWidth: 0.5});

root.render();
document.body.append(renderer.node());