Skip to content

Instantly share code, notes, and snippets.

@JoGall
Created November 4, 2018 16:47
Show Gist options
  • Save JoGall/8ef9b611f432256f9a9fd8017bd5e407 to your computer and use it in GitHub Desktop.
Save JoGall/8ef9b611f432256f9a9fd8017bd5e407 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(soccermatics)
library(StatsBombR)
# get data from StatsBomb
fixture <- FreeMatches(37) %>%
filter(home_team.home_team_name == "Reading WFC" & away_team.away_team_name == "Yeovil Town LFC")
# helper function from my fork of statsbombr package: https://github.com/JoGall/StatsBombR
# or code here: https://github.com/JoGall/StatsBombR/blob/master/R/allinfo.R
d <- allinfo(fixture)
# transform x,y-coords to 105x68m pitch for plotting
d <- soccerTransform(d, method = "statsbomb")
# plots
p1 <- d %>%
filter(team.name == "Reading WFC") %>%
soccerPassmap(fill = "blue", arrow = "r")
p2 <- d %>%
filter(team.name == "Yeovil Town LFC") %>%
soccerPassmap(fill = "green", arrow = "r")
# stitch plots together with cowplot
p <- plot_grid(p1, p2, nrow = 1)
# add title
title <- cowplot::ggdraw() +
cowplot::draw_label("Reading WFC vs. Yeovil Town LFC (2018-09-09)",
fontface = 'bold')
cowplot::plot_grid(title, p, ncol = 1, rel_heights = c(0.1, 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment