2024 Posit Table Contest Entry

2023-24 Scottish Premiership

Author

Diarmuid Lloyd

🏴󠁧󠁢󠁳󠁣󠁴󠁿 ⚽️ Introduction

Selected 2023-24 statistics of the top-flight league of professional Scottish football, the Scottish Premiership.

The table is built from three scripts run in sequence, although the first can be skipped after the first run:

  1. 0_collect_timeseries.R: Collecting time series data back to the 2000-01 season.

  2. 01_spfl_collect_data.R: Wrangling the data, and calculating summary statistics

  3. 02_build_table_gt.R: Building the table.

Alternatively, run quarto render posit-2024-table-comp.qmd.

The repo with these scripts can be found here.

library(tidyverse)

source("scripts/0_collect_timeseries.R")

source("scripts/01_spfl_collect_data.R")

source("scripts/02_build_table_gt.R")

Data source

Data are sourced from https://www.football-data.co.uk/scotlandm.php. While no specific licence is provided on the website, the maintainers state:

You are free experiment with the data yourselves, but if you are looking for a bespoke Excel application that has been desinged specifically to work with Football-Data’s files, visit  BetGPS for an exceptional data analysis workbook. Like all of Football-Data’s files, it free to download.

The accompanying notes provide full sources for the data, but are summarised as:

Current results (full time, half time)
XScores - http://www.xscores .com

Match statistics
BBC, ESPN Soccer, Bundesliga.de, Gazzetta.it and Football.fr

Bookmakers betting odds
Individual bookmakers

Betting odds for weekend games are collected Friday afternoons, and on Tuesday afternoons for midweek games.

Additional match statistics (corners, shots, bookings, referee etc.) for the 2000/01 and 2001/02 seasons for the English, Scottish and German leagues were provided by Sports.com (now under new ownership and no longer available).

Table

The table is built in gt and gtExtra. I relied heavily on the latter’s help files, and Albert Rapp’s tutorial on creating plots within table cells, and I particularly wanted to explore how sparklines and other in-cell plots can help summarise tabular data. While I didn’t exploit the functionality of embedding ggplot2 objects in cells, I think that route would help communicate more data.

final_table
2023–24 Scottish Premiership
This table shows the final league position of football clubs competing in the 2023-24 Scottish Premiership, with selected season statistics, such as goals scored, penalty cards received and matches won.

The division was formed in 2013 and constitutes 12 teams, each of which play 38 matches. Rangers and Celtic generally dominate the division owing to superior resources.
Position Club Goals scored in the... Penalty cards received which were... Swing: Changes between half-time and full-time results Match outcomes Matches won relative to previous seasons1 Points
First half||Second half Yellow||Red non-losing HT → FT loss non-win HT → FT win
1 Celtic 4352 472 1 10 93
2 Rangers 3948 395 2 6 85
3 Hearts 2034 710 3 11 68
4 Kilmarnock 1828 854 4 7 56
5 St Mirren 2224 573 7 4 47
6 Dundee 1930 693 7 6 42
7 Aberdeen 2226 622 6 6 48
8 Hibernian 2131 681 5 2 46
9 Motherwell 2135 804 7 4 43
10 St Johnstone 1316 823 7 4 35
11 Ross County 1523 873 7 4 35
12 Livingston 1118 682 10 2 25
Data: https://www.football-data.co.uk | Table: @dplloyd

Notes
The Scottish Premiership splits into equal-sized top and bottom groups after 33 matches. The remaining five matches played by each team are all within their respective group. As such, a team can finish with more points than another team with a better overall table placement.
1 Vertical lines are median matches won per season between 2000-01 and 2023-24, for each season the relevant team was in the Premiership. While the Premiership formed its current iteration in 2013 following a merger between the Scottish Premier League and the Scottish Football League, twelve teams have competed in the top-flight since 2000-01.