-
Notifications
You must be signed in to change notification settings - Fork 682
/
scales.qmd
28 lines (21 loc) · 1.51 KB
/
scales.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Scales {#sec-scales .unnumbered}
```{r}
#| echo: false
#| message: false
#| results: asis
source("common.R")
```
\index{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:
- Position scales and axes are described in @sec-scale-position.
- Colour scales and legends are described in @sec-scale-colour.
- Scales for other aesthetics are described in @sec-scale-other.
The theory of scales is covered in @sec-scales-guides, which expands on these chapters as well as other sections in the book that refer to scales (e.g., @sec-titles is extended by @sec-scale-names).