Skip to content

Brushing Parallel Coordinates ​

Penguins in parallel coordinates, with a brush of each axis: brushing along an axis keeps the penguins in its range colored, and the others gray; brushing several axes keeps those in all of them, as one clause of the selection. The brushes choose the penguins by their measures, as cm.fold keeps each penguin as the datum of its rows, so that the line of a penguin is chosen as one. Drag along an axis to brush it (a drag anywhere brushes the nearest axis); click an axis to clear its brush. After G2 and Observable Plot.

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 brush = cm.selection();

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, {stroke: brush.match((d) => d.stroke, "#ddd"), strokeOpacity: brush.match(0.5, 0.2, 0.3)})
  .add(cm.brushY, {as: brush, by: "x"});

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