-
Notifications
You must be signed in to change notification settings - Fork 0
/
06_workbook.Rmd
72 lines (57 loc) · 1.34 KB
/
06_workbook.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
---
title: "Data Munging for Data Visualization"
author: "Aaron R. Williams"
output:
html_document:
code_folding: show
toc: TRUE
toc_float: TRUE
editor_options:
chunk_output_type: console
---
```{r}
library(tidyverse)
library(here)
```
## Exercise 1
```{r}
tribble(
~Class, ~female_passengers, ~male_passengers,
"1st class", 144, 179,
"2nd class", 106, 171,
"3rd class", 216, 493
) %>%
pivot_longer(
cols = c(male_passengers, female_passengers),
names_to = "Sex",
values_to = "n"
)
## YOUR WORK GOES HERE
```
## Exercise 2
```{r}
tribble(
~Class, ~`male passengers|female passengers`,
"1st class", "179|144",
"2nd class", "171|106",
"3rd class", "493|216",
)
## YOUR WORK GOES HERE
```
## Exercise 3
```{r}
tribble(
~Class, ~Sex, ~n,
"1st class", "female passengers", 144,
"1st class", "male passengers", 179,
"2nd class", "female passengers", 106,
"2nd class", "male passengers", 171,
"3rd class", "female passengers", 216,
"3rd class", "male passengers", 493
) %>%
filter(Sex != "male_passengers") %>%
# puts first class on top
mutate(Class = factor(Class, levels = c("3rd class", "2nd class", "1st class"))) %>%
ggplot(mapping = aes(x = n, y = Class)) + geom_col(fill = "pink")
## YOUR WORK GOES HERE
```