Three Lions - Baddiel and Skinner

Soccer Aesthetics

Reading Nicholas Rougeux’s recent work on subway systems, I was thinking about extending it to soccer. The obvious comparison is to the colours of soccer shirts. After playing around a bit with coding, I settled on doing it for national teams first due to prevalence of data.

All the shirts used come from a megapack of football manager 2016 kits with the national ones produced by shooto.

Scraping National Team ELO Rankings

To weight the kit colours, I decided on using the world ELO soccer rankings using some code Ihad from a previous project:

library(rvest)
library(magrittr)

#scrape details of clubs and their ELO in europe
url <- "http://www.eloratings.net/world.html"
read <- read_html(url) %>% html_nodes("table:nth-child(6)")

#scrape the countries in the table
nation <- read %>% html_nodes("td:nth-child(2) > a") %>% html_text()

#scrape the ELO ratings
ELO <- read %>% html_nodes("td:nth-child(3)") %>% html_text()
ELO <- ELO[-c(which(ELO == "rating" | ELO == "rank"))]

#put together in data frame
df_WorldELO <- data.frame(Nation = nation, ELO = ELO)
df_WorldELO$Nation <- as.character(df_WorldELO$Nation)
df_WorldELO$ELO <- as.numeric(as.character(df_WorldELO$ELO))

head(df_WorldELO)
##      Nation  ELO
## 1    Brazil 2044
## 2 Argentina 2027
## 3   Germany 2016
## 4    France 1988
## 5     Chile 1963
## 6     Spain 1960

I then saved this and used an eyedropper tool to manualy add in the primary and secondary colours of each kit to a .csv file.

For this I used my gut more than any objective measure. I tried to avoid white/black as much as possible and chose colours on the main body over ones on the sleeves.

Producing the Table Plot

Once this .csv is created we can load it up and check the colours in a quick pie chart.

#set up directory
wd <- "C:/Users/hickman/Desktop/Code/Soccer Aesthetics"
setwd(wd)

#load file
df <- read.csv("worldelo.csv", stringsAsFactors = FALSE, na.strings = "")
  df <- df[-c(which(is.na(df$filename))),]
  df$filename <- paste0(wd, "/National Teams/", df$filename, ".png")

#make a quick plot of the main colours
pie(1:nrow(df), labels = df$Nation, col = df$colourbin,
    main = "Palette of Football Shirts", cex.main=1)

#convert the off-whites to white
df$Colour1[which(df$colourbin == "white")] <- "#FFFFFF"

Due to the shadow on the PNG files, the white comes off slightly off-white, so I set all those teams colours to pure white (#FFFFFF).

We can then use the treemap package to make a treemap files (which isn’t plotted) and pass that into highcharter to create our interative graphic.

TO make slightly more pleasing graphs, the output is actually the ELO^5th power vs. primary colour (ELOs are just a bit too bunched otherwise).

library(treemap)
library(highcharter)
## Highcharts (www.highcharts.com) is a
## Highsoft software product which is
## not free for commercial and Governmental use
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#weight the ELO for more dramatic effect
df$ELOcube <- df$ELO^5

#create a basic treemap
tm <- treemap(df, c("colourbin", "Nation"), "ELOcube", "Colour1", draw = FALSE)

#join our data frame to the treemap
tm$tm <- left_join(tm$tm, df, by = "Nation")
  tm$tm$color <- tm$tm$Colour1

#create a highchart treemap
set.seed(3459)
hctm <- highchart() %>% 
    hc_add_series_treemap(tm, allowDrillToNode = TRUE,
                          layoutAlgorithm = "squarified") %>%
    hc_title(text = "National Soccer Team Shirt Colour vs. Strength") %>%
    hc_tooltip(pointFormat = "<b>{point.name}</b>:<br>
                                ELO: {point.ELO}")

#plot
htmltools::tagList(hctm)

Best,