-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSC_Marathon.R
103 lines (89 loc) · 2.63 KB
/
SC_Marathon.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
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
library(tidyverse)
library(lubridate)
library(camcorder)
library(showtext)
library(ggtext)
# Set fonts
font_add_google("Fira Sans Extra Condensed","cond")
font_add_google("Fira Sans","fira")
font_add_google("Raleway","ral")
font_add_google("Bitter","bit")
font_add_google("Calistoga","cal")
showtext_auto()
# Plot size
gg_record(
dir = file.path(tempdir(),"recording"),
device = "png",
width = 14.3,
height = 30.9,
units = "cm",
dpi = 300
)
winners <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2023/2023-04-25/winners.csv')
women<-winners%>%
filter(Category%in%c("Women"))%>%
select(year=Year,time_women=Time)
men<-winners%>%
filter(Category%in%c("Men"))%>%
select(year=Year,time_men=Time)
clean<-men%>%
left_join(women)%>%
mutate(
tmen=as.numeric(time_men),
twomen=as.numeric(time_women)
)%>%
select(year,tmen,twomen)%>%
add_row(year=2023,tmen=2*3600+60+25,twomen=2*3600+18*60+33)%>%
mutate(
diff=twomen-tmen,
off=tmen+(twomen-tmen)/2
)
pal<-c(
"#FFECD1",
"#FFDA74",
"#FFCA3A",
"#FFAB2D",
"#FF8B1F"
)
col_ax <- "grey80"
ggplot(clean)+
annotate("segment",x=7200,xend=7200,y=-2023.5,yend=-1980,color=col_ax,size=0.1)+
annotate("segment",x=7800,xend=7800,y=-2023.5,yend=-1980,color=col_ax,size=0.1)+
annotate("segment",x=8400,xend=8400,y=-2023.5,yend=-1980,color=col_ax,size=0.1)+
annotate("segment",x=9000,xend=9000,y=-2023.5,yend=-1980,color=col_ax,size=0.1)+
geom_segment(
aes(x=tmen,xend=twomen,y=-year,yend=-year,color=-diff),
size=7
)+
geom_text(
aes(x=off,y=-year,label=year),size=10,family="ral"
)+
scale_x_continuous(limits=c(7100,9500))+
scale_y_continuous(limits=c(-2024,-1979))+
binned_scale(
aesthetics = "color",
scale_name = "stepsn",
palette = function(x) pal,
breaks = c(-1200,-960,-720,-480),
labels = c("20","16","12","8"),
na.value = NA,
show.limits = FALSE,
guide = guide_colorsteps(
nrow=1,
direction = "horizontal",
barheight = unit(4, units = "mm") ,
barwidth = unit(25, units = "mm"),
title.position = 'top',
label.position = "bottom"
))+
theme_void()+
guides(
title="Mind the gap",
subtitle="Evolution of the time gap between women and men winners of the London Marathon from 1981 to 2022",
)+
theme(
legend.position = c(0.875,0.825),
legend.text = element_text(family="fira",color="white",size=26),
legend.title=element_blank(),
panel.background = element_rect(fill="#1D201F",color=NA)
)