Skip to content

Scatterplot of Pies ​

Each lake at its location, drawn as a pie of its catch by species. The pies are charts nested in the rows of the scatterplot: one group per lake, whose data is that lake's catch, drawn in polar coordinates inside the lake's box. After GoFish.

js
const lakes = await d3.csv("/data/seafood-locations.csv", d3.autoType);
const seafood = await d3.csv("/data/seafood.csv", d3.autoType);

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

root
  .data(lakes)
  .transform(cm.encode, {x: "x", y: "y"})
  .transform(cm.plane, {margin: 40, marginLeft: 60}) // room for the pies
  .append(cm.g)
  .data((lake) => seafood.filter((d) => d.lake === lake.lake))
  .transform(cm.encode, {x: "count", fill: "species"})
  .transform(cm.stackX)
  .transform(cm.polar, {width: 40, height: 40, resolve: {x: "independent"}})
  .add(cm.arc, {stroke: "white"});

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