Part 56 Scales

A ggplot is constructed with a flow like this:

data -> stat -> scale -> mapping -> render

The “scale” step concerns how the computed data/stat corresponds to numbers/values on the plot (e.g., “20 mpg” corresponds to a point “3 units up on the y axis”; “4 cylinder” corresponds to “blue”).

You control how values are scaled using the scale_*() functions. Almost every aesthetic you can map to data (e.g., x, y, color, fill, alpha, linetype, shape, size, radius) has corresponding scale functions.

These functions all have the following form:

scale_[aesthetic]_[type]

The scale_*() functions include many arguments to control various features of the scale, depending on the aesthetic.