/
plots.R
71 lines (64 loc) · 1.6 KB
/
plots.R
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
library(tidyverse)
# read in data
london_marathon <- read_csv("london_marathon.csv")
winners <- read_csv("winners.csv")
# london marathon plot
london_plot <- london_marathon %>%
filter(Year < 2020) %>%
mutate(Year = factor(Year))
ggplot(
data = london_plot,
mapping = aes(y = Year)
) +
geom_point(aes(x = Starters),
colour = "#008080"
) +
geom_point(aes(x = Finishers),
colour = "#800080"
) +
geom_segment(aes(
x = Starters,
xend = Finishers,
y = Year,
yend = Year
)) +
labs(
x = "Number of runners",
title = "Number of London Marathon Starters and Finishers"
) +
theme_minimal() +
theme(
axis.title.y = element_blank(),
plot.background = element_rect(fill = "white", colour = "white"),
panel.background = element_rect(fill = "white", colour = "white")
)
ggsave(filename = "london_marathon.png", height = 7, width = 5)
# winners plot
winners_plot <- winners %>%
group_by(Nationality) %>%
summarise(n = n())
ggplot(
data = winners_plot,
mapping = aes(
y = reorder(Nationality, n),
x = n
)
) +
geom_col(fill = "#e00601") +
geom_text(aes(label = n),
colour = "#e00601",
hjust = -1
) +
labs(
x = "Number of winners",
title = "Nationality of London Marathon Winners"
) +
scale_x_continuous(limits = c(0, 50)) +
coord_cartesian(expand = FALSE) +
theme_minimal() +
theme(
axis.title.y = element_blank(),
plot.background = element_rect(fill = "white", colour = "white"),
panel.background = element_rect(fill = "white", colour = "white")
)
ggsave(filename = "winners.png", height = 7, width = 5)