-
Notifications
You must be signed in to change notification settings - Fork 68
/
21_06_07_MarioKart.Rmd
144 lines (126 loc) · 3.19 KB
/
21_06_07_MarioKart.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
---
title: "Guided Tidy Tuesday 06-05-21: Mario Kart"
author: "Kyla McConnell"
date: "7/6/2021"
output: html_document
---
# Guided Tidy Tuesday: Mario Kart
```{r}
library(tidyverse)
records <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-05-25/records.csv')
drivers <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-05-25/drivers.csv')
```
## Look at data
```{r}
glimpse(records)
summary(records)
str(records)
head(records)
```
```{r}
records %>%
mutate(track = as.factor(track),
type = as.factor(type))
(records <- records %>%
mutate(across(where(is.character), as.factor)))
```
How did the world records develop over time?
Which track is the fastest?
For which track did the world record improve the most?
For how many tracks have shortcuts been discovered?
When were shortcuts discovered?
On which track does the shortcut save the most time?
Which is the longest standing world record?
Who is the player with the most world records?
Who are recent players?
Which loop is the most difficult?
Fastest tracks
Longest records
Duration of record by track
Players vs number of shortcuts
```{r}
single_lap <- records %>%
filter(type == "Single Lap")
records %>%
group_by(track, type, shortcut) %>%
summarize(min_time = min(time)) %>%
ggplot() +
aes(y = fct_reorder(track, desc(min_time)), x = min_time, fill = type) +
geom_col(position = "dodge") +
theme_minimal() +
labs(
title = "Records on Mario Kart Tracks",
y = "Record time",
x = "Track"
) +
facet_wrap(type ~ shortcut)
```
Shortcuts:
How many have shortcuts?
When were they discovered?
How much time do they save?
```{r}
records %>%
filter(shortcut == "Yes") %>%
distinct(track)
```
```{r}
records %>%
mutate(year = lubridate::year(date)) %>%
filter(shortcut == "Yes") %>%
group_by(track) %>%
summarize(discovered = min(date)) %>%
arrange(discovered)
```
```{r}
records %>%
filter(shortcut == "Yes") %>%
count(player) %>%
arrange(desc(n))
```
```{r}
records %>%
group_by(track, shortcut) %>%
summarize(fastest = min(time)) %>%
pivot_wider(names_from = shortcut, values_from = fastest) %>%
mutate(Difference = No - Yes)
```
```{r}
kart <- drivers %>%
distinct(player, nation) %>%
full_join(records)
kart %>%
drop_na(nation) %>%
ggplot(aes(y = fct_infreq(nation), fill = nation)) +
geom_bar() +
theme_minimal() +
theme(
legend.position = "None"
) +
labs(
title = "Records by country",
y = "Country",
x = "# of Records"
)
```
```{r}
records %>%
group_by(track, shortcut) %>%
summarise(fastest = min(time)) %>%
ungroup() %>%
pivot_wider(names_from = shortcut, values_from = fastest) %>%
drop_na(Yes) %>%
mutate(time_saved = No - Yes,
track = fct_reorder(track, -Yes)) %>%
ggplot() +
aes(x = track) +
geom_segment(aes(xend = track,
y = Yes, yend = No),
color="grey") +
geom_point(aes(y = Yes),
size = 3, colour = "darkblue", alpha = 0.5) +
geom_point(aes(y = No),
size = 3, colour = "darkgreen", alpha = 0.5) +
coord_flip() +
theme_minimal()
```