Skip to content

Instantly share code, notes, and snippets.

@johnburnmurdoch
Created December 18, 2018 17:57
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnburnmurdoch/1b3f32aaf7757733bd68a6513ab86226 to your computer and use it in GitHub Desktop.
Save johnburnmurdoch/1b3f32aaf7757733bd68a6513ab86226 to your computer and use it in GitHub Desktop.
Scripts for downloading and visualising data from clubelo.com showing José Mourinho’s third season problem. A hand-finished version of this chart appears in this Financial Times story: https://www.ft.com/content/56acdd82-02d2-11e9-99df-6183d3002ee1
needs(tidyverse, magrittr, scales)
jose.porto <- read_csv("http://api.clubelo.com/porto")
jose.chelsea <- read_csv("http://api.clubelo.com/chelsea")
jose.inter <- read_csv("http://api.clubelo.com/inter")
jose.real <- read_csv("http://api.clubelo.com/realmadrid")
jose.mufc <- read_csv("http://api.clubelo.com/manunited")
jose.all <- bind_rows(
jose.porto %>% filter(From >= as.Date("2002-01-22") & To <= as.Date("2004-06-30")),
jose.chelsea %>%
filter(
(From >= as.Date("2004-07-01") & To <= as.Date("2007-09-19"))
),
jose.chelsea %>%
filter(
(From >= as.Date("2013-07-01") & To <= as.Date("2015-12-17"))
) %>% mutate(Club = "Chelsea 2"),
jose.inter %>% filter(From >= as.Date("2008-07-01") & To <= as.Date("2010-06-30")),
jose.real %>% filter(From >= as.Date("2010-07-01") & To <= as.Date("2013-06-30")),
jose.mufc %>% filter(From >= as.Date("2016-07-01") & To <= as.Date("2018-12-18"))
)
jose.labels <- jose.all %>%
group_by(Club) %>%
top_n(1, Elo)
ggplot(jose.all, aes(To, Elo, group=Club, color=Club)) +
theme_minimal() +
geom_line() +
geom_text(data=jose.labels, aes(y = Elo+10, label=Club)) +
scale_color_discrete(guide=F) +
scale_y_continuous(position = "right") +
scale_x_date(date_breaks="2 years", date_labels="%Y") +
labs(x = "", y = "", subtitle = "Team performance level (Elo rating)", title = "Mourinho’s recent stints have been marked by steep declines in performance after promising starts")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment