Skip to content

Parallel Coordinates ​

The four measures of each penguin, colored by species. cm.fold makes a row of each measure of a penguin, at the measure along x and its value along y; with {y: {by: "x"}}, cm.plane gives each measure its own scale and axis, so that each keeps its units. After G2.

js
const penguins = (await d3.csv("/data/penguins.csv", d3.autoType)).filter((d) => Number.isFinite(d.body_mass_g));
const measures = ["culmen_length_mm", "culmen_depth_mm", "flipper_length_mm", "body_mass_g"];

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

root
  .data(penguins)
  .transform(cm.encode, {stroke: "species"})
  .transform(cm.fold, {x: measures})
  .transform(cm.plane, {y: {by: "x"}, stroke: {legend: true}})
  .add(cm.lineY, {strokeOpacity: 0.3});

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