-
Notifications
You must be signed in to change notification settings - Fork 1
/
ch-15.Rmd
88 lines (65 loc) · 2.29 KB
/
ch-15.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
80
81
82
83
84
85
86
87
88
---
title: "Solutions to Chapter 15 Exercises"
author: "Howard Baek"
date: "Last compiled on `r format(Sys.time(), '%B %d, %Y')`"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, include=FALSE}
library(tidyverse)
```
### 15.1.1 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")
####################################
####################################
```
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.
### 15.7 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**.