Cartesian and Beyond
The coordinate system is the space marks live in — usually Cartesian, but the choice is a real grammar component with real consequences.
The coordinate system is the space your marks are placed in. You have been using one all along — the standard Cartesian plane, x running left-to-right and y bottom-to-top — without naming it. Making it an explicit component unlocks zooming, aspect-ratio control, and (next page) entirely different chart shapes.
The default: Cartesian
coord_cartesian() is the familiar flat plane. It is applied
automatically, so these two are identical:
Coordinates transform the space, not the data
Here is the key mental model. Scales and stats operate in data space — they change values. Coordinates operate on the final space — they reshape where already-computed marks land, after the stats and scales have run.
This ordering is exactly why coord_cartesian(xlim = ...) zooms
rather than filters: the coordinate step happens last, after the
smoother has already been fit on all the data. (We met this on the
Position Scales page — now you can see why.)
Fixing the aspect ratio
coord_fixed() forces one data unit on x to equal one data unit on y —
essential when x and y are in the same units and distances should
be comparable (maps, before/after on the same measurement scale):
With coord_fixed(), the red y = x line is a genuine 45° diagonal,
so you can read "highway beats city MPG" as every point above the
line. Without it, the plot would stretch to fill the panel and distort
that comparison.
Coordinates are a full grammar component
It is tempting to ignore coordinates because the default is almost always right. But treating them as a real, swappable component is what lets the same bar chart become a pie chart, or a Cartesian plot become a map projection.
In the ggplot pipeline, when does the coordinate system act relative to stats and scales?
Before the stat, so it can change which rows are counted.
After stats and scales, arranging the already-computed marks in the final space — which is why coord_cartesian(xlim=) zooms instead of filtering.
At the same time as the mapping.
Coordinates never affect a plot; they are decorative.
Why might you add coord_fixed() to a plot of city MPG vs. highway MPG?
To filter out cars with low MPG.
To convert the axes to a log scale.
Because both axes are in the same units, so equal data distances should look equal — making a y = x reference line a true 45-degree diagonal.
To add a confidence band to the points.
Key takeaways
- The coordinate system is the space marks occupy; Cartesian is the
default (
coord_cartesian()). - Coordinates act last, on the final space — so
coord_cartesian(xlim=)zooms without discarding data. coord_fixed()enforces an equal x/y unit ratio, vital when the axes share units.- Coordinates are a genuine, swappable component — the foundation for the polar and flipped charts on the next page.
Color and Fill Scales
How ggplot2 turns data into color — discrete palettes, continuous gradients, the color vs fill distinction, and choosing perceptually honest scales.
Flipping and Polar Coordinates
The grammar's most striking payoff — turning a bar chart into a pie chart by changing only the coordinate system, and flipping axes the right way.