Skip to content

Letter Frequency in the Terminal ​

The frequency of letters in English, on the terminal renderer: bars filled with color, a grid, and a red rule at 4% drawn with cm.annotate. The ticks are snapped to whole rows, so the grid lines are evenly spaced.

js
const alphabet = await d3.csv("/data/alphabet.csv", d3.autoType);

const renderer = cm.terminal({width: 640, height: 400, units: "pixels"});
const root = cm.flow().renderer(renderer);

root
  .data(alphabet)
  .transform(cm.encode, {x: "letter", y: "frequency"})
  .transform(cm.spreadX)
  .transform(cm.plane, {y: {tickFormat: "%", grid: true}})
  .add(cm.rect, {fill: "steelblue"})
  .add(cm.annotate(cm.link), {y: 0.04, stroke: "red"});

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