-
Notifications
You must be signed in to change notification settings - Fork 90
/
01-Visualize.Rmd
110 lines (67 loc) · 1.7 KB
/
01-Visualize.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
title: "Visualize Data"
output: html_notebook
---
<!-- This file by Charlotte Wickham is licensed under a Creative Commons Attribution 4.0 International License, adapted from the orignal work at https://github.com/rstudio/master-the-tidyverse by RStudio. -->
```{r setup}
library(tidyverse)
```
```{r}
mpg
```
## Quiz
What relationship do you expect to see between engine size (displ) and highway fuel efficiency (hwy)?
## Your Turn 1
Run the code on the slide to make a graph. Pay strict attention to spelling, capitalization, and parentheses!
```{r}
```
## Your Turn 2
Add `color`, `size`, `alpha`, and `shape` aesthetics to your graph. Experiment.
```{r}
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
```
## Your Turn 3
Replace this scatterplot with one that draws boxplots. Use the cheatsheet. Try your best guess.
```{r}
ggplot(data = mpg) +
geom_point(mapping = aes(x = class, y = hwy))
```
## Your Turn 4
Make a histogram of the `hwy` variable from `mpg`.
```{r}
ggplot(data = mpg)
```
## Your Turn 5
Make a density plot of `hwy` colored by `class`.
```{r}
ggplot(data = mpg)
```
## Your Turn 6
Make a bar chart `class` colored by `class`.
```{r}
ggplot(data = mpg)
```
## Your Turn 7
Predict what this code will do. Then run it.
```{r}
ggplot(mpg) +
geom_point(aes(displ, hwy)) +
geom_smooth(aes(displ, hwy))
```
## Your Turn 8
What does `getwd()` return?
```{r}
getwd()
```
## Your Turn 9
Save the last plot and then locate it in the files pane.
```{r}
```
***
# Take aways
You can use this code template to make thousands of graphs with **ggplot2**.
```{r, eval = FALSE}
ggplot(data = <DATA>) +
<GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
```