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 divide scales into three main groups, covered in separate chapters:
- Position scales and axes are described in Chapter 10.
- Colour scales and legends are described in Chapter 11.
- Scales for other aesthetics are described in Chapter 12.