-
Notifications
You must be signed in to change notification settings - Fork 32
/
02_winter_games.rmd
108 lines (86 loc) · 3.08 KB
/
02_winter_games.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
name: wintergamemedals
# Winter Games
```{r, echo = F}
library(tidyverse)
df <- readxl::read_xlsx("raw_data/Winter Olympic Medals.xlsx")
library(knitr)
```
```{r, echo = F}
country_data <- df %>% filter(Year > 1945) %>% group_by(Country) %>% tally() %>% arrange(desc(n))
big_sixteen <- country_data$Country[1:16]
year_data <- df %>% group_by(Year) %>% summarise(number_of_medals_year = n())
year_country_data <-
df %>%
group_by(Year, Country) %>%
summarise(number_of_medals = n()) %>%
left_join(year_data) %>%
mutate(percent_medals = 100 * number_of_medals / number_of_medals_year) %>%
filter(Country %in% big_sixteen)
```
A random sample from the data set:
```{r, echo = F}
dta = year_country_data %>% filter(Year > 1945)
knitr::kable(sample_n(df, 5), format = "html")
```
---
```{r countries_games, eval = F, echo = F}
ggplot(data = dta) +
aes(x = Year) +
aes(y = percent_medals) +
geom_line() +
facet_wrap(~ Country) +
labs(y = "") +
labs(title = "Number of Winter Olympic Medals among 16 most winning countries, 1948-2014") +
labs(caption = "Vis: @EvaMaeRey | Source: Sports-Reference.com") +
theme_minimal()
```
`r paste(knitr::knit(text = partial_knit_chunks("countries_games")), collapse = "\n")`
---
```{r, echo = F}
df_individual <- df %>% filter(Sport != "Bobsled" &
Sport != "Curling" &
Sport != "Ice Hockey" &
Sport != "Skeleton" &
Sport != "Freestyle Skiing" &
Sport != "Snowboarding" &
Sport != "Short-Track Speedskating")
dta <- df_individual %>%
filter(Year > 1945) %>%
mutate(
cold_war =
ifelse(!(Country %in% c("Soviet Union", "East Germany")),
"A", Country
))
```
A random sample from the data set:
```{r, echo = F}
knitr::kable(sample_n(dta, 5), format = "html")
```
---
```{r winter_games, fig.width=10, fig.height=6, eval=F, echo=F}
ggplot(dta) +
aes(x = Year) +
aes(y = `Age of Athlete`) +
facet_wrap(~ Sport, scales = "free_y", nrow = 2) +
geom_jitter(mapping = aes(col = fct_inorder(Medal)),
width = 1, height = .5, size = 1) +
geom_smooth(col = "grey30") +
annotate(geom = "ribbon", x = c(1945,2016),
ymin = 20, ymax = 30,
alpha = .1, fill = "blue") +
geom_hline(yintercept = c(20, 30), lty = "dotted") +
geom_hline(yintercept = c(25), lty = "dashed") +
scale_color_manual(values = c("goldenrod3", "grey40", "goldenrod4")) +
labs(x = "", col = "") +
labs(title = "Young and old at the Winter Olympics: medalists' declared ages have risen in recent years") +
labs(subtitle = "Includes individual sports that have been in Olympic since 1965") +
labs(caption = "Source: Sports-Reference.com | Vis: Gina Reynolds @EvaMaeRey \nValues 'jittered' to reduce overplotting") +
theme_bw(base_size = 13)
```
```{r, echo = F, warning=F, message=F, eval = T, fig.show='hide'}
get_what_save_what <- "winter_games"
eval(parse(text = paste(knitr:::knit_code$get(get_what_save_what), collapse = "")))
ggsave(paste0("figures/", get_what_save_what, ".png"), dpi = 300)
```
`r paste(knitr::knit(text = partial_knit_chunks("winter_games")), collapse = "\n")`
---