-
Notifications
You must be signed in to change notification settings - Fork 2
/
15-scales-guides.Rmd
79 lines (57 loc) · 2.04 KB
/
15-scales-guides.Rmd
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Scales and guides
```{r, include=FALSE}
library(tidyverse)
```
## Exercises
```{r}
####################################
####################################
# ggplot(mpg, aes(displ)) +
# scale_y_continuous("Highway mpg") +
# scale_x_continuous() +
# geom_point(aes(y = hwy))
# The above can be modified to:
# mpg %>%
# ggplot(aes(displ, hwy)) +
# geom_point() +
# labs(y = "Highway mpg")
####################################
####################################
####################################
####################################
# ggplot(mpg, aes(y = displ, x = class)) +
# scale_y_continuous("Displacement (l)") +
# scale_x_discrete("Car type") +
# scale_x_discrete("Type of car") +
# scale_colour_discrete() +
# geom_point(aes(colour = drv)) +
# scale_colour_discrete("Drive\ntrain")
# The above can be modified to
# mpg %>%
# ggplot(aes(class, displ)) +
# geom_point(aes(color = drv)) +
# labs(x = "Type of car",
# y = "Displacement (l)",
# color = "Drive\ntrain")
####################################
####################################
```
<br>
**2.** What happens if you pair a discrete variable with a continuous scale? What happens if you pair a continuous variable with a discrete scale?
```{r}
mpg %>%
ggplot(aes(class, displ)) +
geom_point(aes(color = drv)) +
scale_y_discrete() +
labs(x = "Type of car",
y = "Displacement (l)",
color = "Drive\ntrain")
```
- When you pair a discrete variable with a continuous scale, you don't see a plot and get this error message: _Discrete value supplied to continuous scale_
- When you pair a continuous variable with a discrete scale, as seen above, you get a different looking plot that doesn't contain the proper axis ticks or grid lines.
<br>
## Exercises
According to the help pages,
- `name`: specifies the labels for **axis** and the title for **legends**.
- `breaks`: specifies the ticks and grid lines for **axis** and the key for **legends**.
- `labels`: specifies the tick label for **axis** and key label for **legends**.