Instantly share code, notes, and snippets.

Embed
What would you like to do?
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