forked from dgrtwo/data-screencasts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2020_12_15_ninja_warrior.Rmd
302 lines (231 loc) · 8.17 KB
/
2020_12_15_ninja_warrior.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
---
title: "TidyTemplate"
date: 2020-12-15
output: html_output
---
# TidyTuesday
Join the R4DS Online Learning Community in the weekly #TidyTuesday event!
Every week we post a raw dataset, a chart or article related to that dataset, and ask you to explore the data.
While the dataset will be “tamed”, it will not always be tidy! As such you might need to apply various R for Data Science techniques to wrangle the data into a true tidy format.
The goal of TidyTuesday is to apply your R skills, get feedback, explore other’s work, and connect with the greater #RStats community!
As such we encourage everyone of all skills to participate!
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(tidytuesdayR)
library(scales)
theme_set(theme_light())
```
# Load the weekly Data
Dowload the weekly data and make available in the `tt` object.
```{r Load}
tt <- tt_load("2020-12-15")
ninja_warrior <- tt$ninja_warrior %>%
mutate(round_stage = str_remove(round_stage, " \\(Regional/City\\)"))
```
```{r}
ninja_warrior %>%
count(location, sort = TRUE)
ninja_warrior %>%
count(round_stage, obstacle_name, sort = TRUE)
ninja_warrior %>%
filter(location == "Venice") %>%
View()
ninja_warrior %>%
count(location, round_stage, sort = T) %>%
view()
ninja_warrior %>%
filter(!str_detect(round_stage, "National")) %>%
count(season, location, round_stage) %>%
ggplot(aes(n, fill = round_stage)) +
geom_histogram() +
scale_x_continuous(breaks = 1:10) +
labs(x = "# of obstacles")
ninja_warrior %>%
count(round_stage, sort = TRUE)
```
```{r}
library(tidylo)
ninja_warrior %>%
filter(round_stage %in% c("Qualifying", "Finals")) %>%
count(round_stage, obstacle_name, sort = TRUE) %>%
bind_log_odds(round_stage, obstacle_name, n) %>%
arrange(desc(log_odds_weighted)) %>%
filter(round_stage == "Finals") %>%
top_n(16, abs(log_odds_weighted)) %>%
mutate(obstacle_name = fct_reorder(obstacle_name, log_odds_weighted)) %>%
ggplot(aes(log_odds_weighted, obstacle_name)) +
geom_col() +
labs(x = "More / less likely in finals")
```
```{r}
total_rounds <- ninja_warrior %>%
filter(round_stage == "Qualifying") %>%
distinct(season, location) %>%
nrow()
library(tidytext)
ninja_warrior %>%
filter(round_stage %in% c("Qualifying", "Finals")) %>%
unite(season_location, season, location, remove = FALSE) %>%
group_by(round_stage) %>%
mutate(total_rounds = n_distinct(season_location)) %>%
group_by(round_stage, obstacle_name) %>%
summarize(avg_position = mean(obstacle_order),
n_rounds = n(),
pct_rounds = n_rounds / first(total_rounds)) %>%
arrange(desc(n_rounds)) %>%
top_n(10, n_rounds) %>%
ungroup() %>%
mutate(obstacle_name = reorder_within(obstacle_name, avg_position, round_stage)) %>%
ggplot(aes(avg_position, obstacle_name, size = pct_rounds)) +
geom_point() +
facet_wrap(~ round_stage, nrow = 2, scales = "free_y") +
scale_x_continuous(breaks = 1:10) +
scale_y_reordered() +
scale_size_continuous(labels = percent) +
labs(x = "Average position within the obstacle course",
y = "",
size = "% of courses")
```
```{r}
visualize_steps <- function(tbl) {
tbl %>%
add_count(obstacle_order, round_stage, name = "round_stage_total") %>%
filter(round_stage_total >= 10) %>%
mutate(obstacle_name = fct_lump(obstacle_name, 10)) %>%
mutate(obstacle_name = fct_reorder(obstacle_name, obstacle_order)) %>%
count(round_stage_total, obstacle_name, obstacle_order) %>%
ggplot(aes(obstacle_order, n / round_stage_total, fill = obstacle_name)) +
geom_col(width = 1) +
scale_x_continuous(breaks = 1:10) +
scale_y_continuous(labels = percent) +
labs(x = "Step",
y = "% of courses",
fill = "Obstacle")
}
ninja_warrior %>%
filter(round_stage == "Qualifying") %>%
visualize_steps() +
labs(title = "What does a typical Qualifying course look like?")
ninja_warrior %>%
filter(round_stage == "Finals") %>%
visualize_steps() +
labs(title = "What does a typical Finals course look like?")
ninja_warrior %>%
filter(round_stage == "Finals") %>%
visualize_steps() +
labs(title = "What does a typical Finals course look like?") +
facet_wrap(~ obstacle_name) +
theme(legend.position = "none")
```
```{r}
library(glue)
ninja_warrior %>%
filter(round_stage == "Qualifying") %>%
add_count(obstacle_order, round_stage, name = "round_stage_total") %>%
filter(round_stage_total >= 10) %>%
add_count(obstacle_name, name = "obstacle_total") %>%
mutate(obstacle_name = glue("{ obstacle_name } ({ obstacle_total })")) %>%
mutate(obstacle_name = fct_lump(obstacle_name, 10)) %>%
mutate(obstacle_name = fct_reorder(obstacle_name, obstacle_order)) %>%
ggplot(aes(obstacle_order, obstacle_name)) +
geom_boxplot() +
scale_x_continuous(breaks = 1:10) +
labs(x = "Step",
y = "% of courses",
fill = "Obstacle")
```
Conclusions:
* Always starts with (Floating/Quad/Quintuple) Steps, always ends with Warped/Mega Wall
* Most common second steps include Log Grip/Rolling Log
* Most common third step is Bridge of Blades
* Most common fourth step is Jump Hang
* Fifth is a "wild card"
Finals:
* Always starts with Archer/Floating/Quad/Quintuple Steps
* Always ends with Elevator/Spider Climb, Spider Trap, occasionally Cargo Climb
* Almost always has a Salmon Ladder around step 7
```{r}
ninja_warrior %>%
filter(round_stage == "Qualifying",
obstacle_order <= 6) %>%
mutate(lumped = fct_lump(obstacle_name, 12),
lumped = fct_reorder(lumped, obstacle_order + season * .01)) %>%
unite(season_location, season, location, sep = " - ", remove = FALSE) %>%
mutate(season_location = fct_rev(fct_reorder(season_location, season))) %>%
ggplot(aes(obstacle_order, season_location, fill = lumped)) +
geom_tile() +
geom_text(aes(label = obstacle_name), size = 3) +
theme(legend.position = "none") +
scale_x_continuous(breaks = 1:6) +
labs(x = "Step",
y = "")
ninja_warrior %>%
filter(round_stage == "Finals",
obstacle_order <= 10) %>%
mutate(obstacle_name = str_trunc(obstacle_name, 15),
lumped = fct_lump(obstacle_name, 12),
lumped = fct_reorder(lumped, obstacle_order + season * .01)) %>%
unite(season_location, season, location, sep = " - ", remove = FALSE) %>%
mutate(season_location = fct_rev(fct_reorder(season_location, season))) %>%
ggplot(aes(obstacle_order, season_location, fill = lumped)) +
geom_tile() +
geom_text(aes(label = obstacle_name), size = 3) +
theme(legend.position = "none") +
scale_x_continuous(breaks = 1:10) +
labs(x = "Step",
y = "")
```
```{r}
ninja_warrior %>%
filter(round_stage == "Qualifying") %>%
mutate(obstacle_name = fct_lump(obstacle_name, 15)) %>%
mutate(obstacle_name = fct_reorder(obstacle_name, season)) %>%
ggplot(aes(season, obstacle_name)) +
geom_boxplot() +
scale_x_continuous(breaks = 1:10)
ninja_warrior %>%
filter(round_stage == "Qualifying") %>%
mutate(obstacle_name = fct_lump(obstacle_name, 8)) %>%
mutate(obstacle_name = fct_rev(fct_reorder(obstacle_name, season))) %>%
count(obstacle_name, season) %>%
group_by(season) %>%
mutate(pct = n / sum(n)) %>%
ggplot(aes(season, pct, fill = obstacle_name)) +
geom_col() +
scale_x_continuous(breaks = 1:10) +
scale_y_continuous(labels = percent) +
labs(y = "% of obstacles")
```
```{r}
ninja_warrior %>%
filter()
```
# Readme
Take a look at the readme for the weekly data to get insight on the dataset.
This includes a data dictionary, source, and a link to an article on the data.
```{r Readme, eval = interactive()}
tt
```
# Glimpse Data
Take an initial look at the format of the data available.
```{r Glimpse}
tt %>%
map(glimpse)
```
# Wrangle
Explore the data and process it into a nice format for plotting! Access each dataset by name by using a dollarsign after the `tt` object and then the name of the data set.
```{r Wrangle}
```
# Visualize
Using your processed dataset, create your unique visualization.
```{r Visualize}
```
# Save Image
Save your image for sharing. Be sure to use the `#TidyTuesday` hashtag in your post on twitter!
```{r}
# This will save your most recent plot
ggsave(
filename = "My TidyTuesday Plot.png",
device = "png")
```