Skip to content
← ML

/knowledge/notes/grammar-of-graphics

Concept note · ML

Grammar of Graphics

Data Visualization

Studied
Self-study
When
2024
Applied in
Every project
Read / Refreshed
~5 min read2026-10-15

A chart is not a named template (bar, scatter, line). It is a composition of layers: data mapped to aesthetics (x, y, colour), rendered as geoms (points, bars), with scales and coordinates. ggplot2 implements this grammar, letting you build any chart from a few rules.

01

The idea

The grammar has seven layers: data (the dataframe), aesthetics (x, y, colour, size), geoms (visual marks: points, bars, lines), stats (transformations: bin, smooth), scales (map data to visual properties), coordinates (Cartesian, polar), and facets (small multiples). Each is independent; changing one does not break others.

A scatter plot is data + aes(x, y) + geom_point(). A histogram is data + aes(x) + geom_histogram(), which bins x (a stat) and renders bars (a geom). Colour, facets, and scales are added orthogonally. This composability replaces 40+ named chart types with a syntax that describes what you see.

02

The maths

03

Try it

1 / 7 layers enabled
1 of 7 layers active
Interactive demonstration of data visualization concepts

04

Where I used it

05

Easy to get wrong

06

Sources

Self-study of ggplot2 and Wilkinson's grammar (2024).