Created
December 22, 2018 04:47
-
-
Save Ryo-N7/2067e6c63f66ca7a7039b114d51bd40d to your computer and use it in GitHub Desktop.
Klopp's Managerial History
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pacman::p_load(tidyverse, scales, lubridate, ggrepel, glue, extrafont) | |
loadfonts() | |
lfc_elo_raw <- read_csv("http://api.clubelo.com/liverpool") | |
dortmund_elo_raw <- read_csv("http://api.clubelo.com/Dortmund") | |
mainz_elo_raw <- read_csv("http://api.clubelo.com/Mainz") | |
mainz_elo_clean <- mainz_elo_raw %>% | |
filter(between(From, as.Date("2001-02-28"), as.Date("2008-05-19"))) | |
dortmund_elo_clean <- dortmund_elo_raw %>% | |
filter(between(From, as.Date("2008-08-15"), as.Date("2015-05-24"))) | |
lfc_elo_clean <- lfc_elo_raw %>% | |
filter(From >= as.Date("2015-10-05")) | |
klopp <- lfc_elo_clean %>% | |
bind_rows(dortmund_elo_clean, mainz_elo_clean) %>% | |
mutate(Club = as_factor(Club)) | |
# Annotations: | |
# Klopp | |
# Mainz: 2003-2004 Promotion to Bundesliga 2004-05-24 | |
# Dortmund: 2010-2011 2011-05-14 | |
# 2011-2012 Bundesliga champions 2012-05-05 | |
# 2013 Champions League Final 2013-05-25 | |
# LFC: October 2015 2015-10-08 | |
# Europa League Final 2016-05-18 | |
# 2018 Champions League Final 2018-05-26 | |
annotations_df <- data.frame( | |
date = as.Date(c("2004-05-24", "2011-05-15", "2012-05-05", | |
"2013-05-25", "2016-05-18", "2018-05-26")), | |
lab_pos = as.Date(c("2004-05-24", "2009-09-01", "2009-09-01", | |
"2013-05-01", "2016-01-01", "2017-10-01")), | |
y = c(1700, 1920, 1970, 2020, 1970, 2020), | |
text = c("Promotion to Bundesliga ('03-'04)", | |
"Bundesliga Champions ('10-'11)", | |
"Bundesliga Champions ('11-'12)", | |
"2013 Champions League Final", | |
"2016 Europa League Final", | |
"2018 Champions League Final") | |
) | |
# line colors | |
cols <- c("Liverpool" = "#D00027", "Dortmund" = "#FFE500", "Mainz" = "#C4122E") | |
# PLOT: | |
# fig.height = 8, fig.width = 11 | |
klopp %>% | |
ggplot() + | |
geom_line(aes(From, y = Elo, color = Club)) + | |
scale_x_date(breaks = pretty_breaks(10)) + | |
scale_y_continuous(limits = c(1430, 2100), position = "right") + | |
scale_color_manual(values = cols, guide = FALSE) + | |
theme_minimal() + | |
theme(text = element_text(family = "Roboto Condensed"), | |
plot.title = element_text(size = 25), | |
plot.subtitle = element_text(size = 15), | |
plot.caption = element_text(size = 12), | |
axis.title = element_text(size = 18), | |
axis.text = element_text(size = 15)) + | |
labs(x = NULL, y = "Club Elo Rating", | |
title = "Jürgen Klopp's Managerial History", | |
subtitle = glue(" | |
After learning the managerial ropes at Mainz, Klopp has given both Dortmund | |
and Liverpool the adrenaline shot needed to climb back to the top!"), | |
caption = glue(" | |
@R_by_Ryo | |
Source: clubelo.com")) + | |
# Connecting segments: | |
annotate(geom = "segment", | |
x = as.Date("2004-05-24"), xend = as.Date("2004-05-24"), | |
y = 1541.472, yend = 1700) + | |
annotate(geom = "segment", | |
x = as.Date("2011-05-14"), xend = as.Date("2010-01-01"), | |
y = 1844.078, yend = 1920) + | |
annotate(geom = "segment", | |
x = as.Date("2012-05-05"), xend = as.Date("2011-12-01"), | |
y = 1912.054, yend = 1970) + | |
annotate(geom = "segment", | |
x = as.Date("2013-05-01"), xend = as.Date("2013-05-01"), | |
y = 1945.104, yend = 2020) + | |
annotate(geom = "segment", | |
x = as.Date("2016-05-18"), xend = as.Date("2016-03-01"), | |
y = 1800.110, yend = 1970) + | |
annotate(geom = "segment", | |
x = as.Date("2018-05-26"), xend = as.Date("2017-10-01"), | |
y = 1913.713, yend = 2020) + | |
# achievements text: | |
geom_label(data = annotations_df, | |
aes(x = lab_pos, y = y, label = text), | |
family = "Roboto Condensed", size = 4.5) + | |
# Team names + bars: | |
annotate(geom = "segment", | |
x = as.Date("2001-02-28"), xend = as.Date("2008-06-30"), | |
y = 2050, yend = 2050, color = "red") + | |
annotate(geom = "text", | |
x = as.Date("2004-10-29"), y = 2080, | |
label = "Mainz", family = "Roboto Condensed", | |
color = "#C4122E", size = 8) + | |
annotate(geom = "segment", | |
x = as.Date("2008-07-18"), xend = as.Date("2015-06-30"), | |
y = 2050, yend = 2050) + | |
annotate(geom = "text", | |
x = as.Date("2012-01-08"), y = 2080, | |
label = "Borussia Dortmund", family = "Roboto Condensed", | |
size = 8) + | |
annotate(geom = "segment", | |
x = as.Date("2015-10-08"), xend = as.Date("2018-12-30"), | |
y = 2050, yend = 2050, color = "red") + | |
annotate(geom = "text", | |
x = as.Date("2017-05-19"), y = 2080, | |
label = "Liverpool", family = "Roboto Condensed", | |
color = "#D00027", size = 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment