malevich

Start here

Which chart

You have a shape of data. Here is the preset, the plate, and the page that explains it.

You have a shape of data. The preset is the short spelling. The plate is that spelling, drawn. The link is the page that takes the lid off.

One series#

Numbers in order, against the index. The preset is line.

7.5 ┤ │ │ 5.0 ┤ │ 2.5 ┤ │ 0.0 ┤ └┬─────────────┬─────────────┬─────────────┬ 0 1 2 3
Plate 1. line over four values.

Line is the mark. A second series, a title, or a reference line is the grammar, and it prints the same bytes as the preset it grew from.

Categories#

A name and a number. The preset is bar. Bars rise from zero on a band axis.

7.5 ┤ │ │ 5.0 ┤ │ 2.5 ┤ │ 0.0 ┤ └─────────────────────────────────────────── mon tue wed thu fri
Plate 2. bar over a week.

Sideways, stacked, and grouped are the bar mark, not new presets.

A distribution#

One column of measurements, and the shape it makes. The preset is hist. It chooses the bins. The count axis does not label a half.

body mass, g 100 ┤ │ 75 ┤ │ │ 50 ┤ │ 25 ┤ │ 0 ┤ └┬──────────┬──────────┬─────────┬──────────┬──────────┬ 2000 3000 4000 5000 6000 7000 g
Plate 3. hist over 342 penguin body masses.

Bins, percent, and the cumulative climb are the statistics layer.

A density#

The same column, smoothed. The preset is density. The bandwidth is the knob.

kernel density, three bandwidths ── ½ Silverman ── Silverman (default) ── 2× Silverman 600µ ┤ │ 500µ ┤ 400µ ┤ │ 300µ ┤ │ 200µ ┤ │ 100µ ┤ 0 ┤ └┬────────┬────────┬─────────┬────────┬─────────┬────────┬────────┬ 1000 2000 3000 4000 5000 6000 7000 8000 body mass, g
Plate 4. One sample, three bandwidths. Silverman's rule is the middle one.

A box plot#

A number per category, and the spread. The preset is box_plot: type-7 quartiles, Tukey whiskers, outliers.

Range::over with body and marker 230 ┤ f │ l 220 ┤ i │ ━━━━━━━━ p 210 ┤ p │ e 200 ┤ r │ ━━━━━━━━ , 190 ┤ ━━━━━━━━━ │ m 180 ┤ m │ 170 ┤ └───────────────────────────────────────────────────── Adelie Chinstrap Gentoo
Plate 5. The box plot, spelled with Range: whiskers, a body from q1 to q3, a marker at the median.

A violin#

The shape per category, instead of the five numbers. The preset is violin. It is two horizontal areas around a kernel density.

a violin is two horizontal areas Area::horizontal f 240 ┤ l │ i 230 ┤ p │ p │ e 220 ┤ r │ , │ 210 ┤ m │ m 200 ┤ │ └┬────────┬───────┬────────┬────────┬────────┬───────┬ -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06
Plate 6. One violin, spelled as two horizontal areas.

Two columns#

An x and a y. The preset is scatter.

penguin bills d 22 ┤ e │ p 20 ┤ t │ h 18 ┤ , │ 16 ┤ m │ m 14 ┤ │ └┬────────┬────────┬────────┬───────┬────────┬────────┬ 30 35 40 45 50 55 60 length, mm
Plate 7. scatter over two columns.

Categories on a scatter#

The same two columns, and a name for each point. color_by paints the groups, names them in the legend, and cycles marker shapes when the output has no color.

flipper length against body mass •• Adelie •• Chinstrap •• Gentoo │ 6000 ┤ │ │ 5000 ┤ │ g │ │ 4000 ┤ │ │ 3000 ┤ │ └┬─────────┬──────────┬─────────┬─────────┬──────────┬─────────┬─ 170 180 190 200 210 220 230 mm
Plate 8. Three species, one color_by channel.

The grammar builds this up one layer at a time.

A matrix#

Rows, columns, and a value in each cell. The preset is heatmap.

Cells::matrix — a value grid under a colormap │ Jan ┤ 35 Feb ┤ │ ▓ 30 Mar ┤ ▓ │ ▓ Apr ┤ ▒ 25 │ ▒ May ┤ ░ 20 Jun ┤ ░ │ ░ └────────────────────────────────────────────────────── 15 00 04 08 12 16 20
Plate 9. Cells::matrix under a colormap. heatmap is the short spelling.

A logarithmic colormap, for weights that span decades, is scales.

Calendar time#

A timestamp and a number. The axis reads the span and labels hours, days, or years. You do not hand it a format string.

CO₂ at Mauna Loa (NOAA) 440 ┤ │ 420 ┤ │ 400 ┤ p │ p 380 ┤ m │ 360 ┤ │ 340 ┤ │ 320 ┤ └─┬─────────┬────────┬─────────┬────────┬─────────┬────────┬────── 1960 1970 1980 1990 2000 2010 2020
Plate 10. Monthly CO₂ at Mauna Loa, 1958 onward, on a calendar axis.

A table first#

The summary you usually compute before you plot anything. The preset is describe.

flipper length, mm │ Adelie ┤ 151 190.0 6.539 172 186 190 195 210 Chinstrap ┤ 68 195.8 7.132 178 191 196 201 212 Gentoo ┤ 123 217.2 6.485 203 212 216 221 231 │ └───────────────────────────────────────────────────────────────────── count mean sd min p25 p50 p75 max
Plate 11. describe: count, mean, sd, min, quartiles, max. A gap is an em dash.

More points than pixels#

A long line. Past four points per column, the plot inserts M4 — first, last, minimum, and maximum in each column — and the pixels match drawing every point. A spike one sample wide stays.

200,000 points through M4 8 ┤ │ 6 ┤ 4 ┤ │ 2 ┤ │ 0 ┤ │ -2 ┤ -4 ┤ └┬────────┬─────────┬────────┬─────────┬────────┬────────┬─────────┬────────┬ 0 25k 50k 75k 100k 125k 150k 175k 200k
Plate 12. 200,000 points. The three one-sample spikes survive.

The measurement is on the performance page.