Scales

Scales in ggplot2 control the mapping from data to aesthetics. They take your data and turn it into something that you can see, like size, colour, position or shape. They also provide the tools that let you interpret the plot: the axes and legends. You can generate plots with ggplot2 without knowing how scales work, but understanding scales and learning how to manipulate them will give you much more control.

In ggplot2, guides are produced automatically based on the layers in your plot. You don’t directly control the legends and axes; instead, you set up the data so that there’s a clear mapping between data and aesthetics, and a guide is generated for you. This is very different to base R graphics, where you have total control over the legend, and can be frustrating when you first start using ggplot2. However, once you get the hang of it, you’ll find that it saves you time, and there is little you cannot do.

The scales toolbox divides scales into three main groups, covered in separate chapters:

The theory of scales is covered in Chapter 14, which expands on these chapters as well as other sections in the book that refer to scales (e.g., Section 8.1 is extended by Section 14.2).