Soccermatics for football analytics with Bayer Leverkusen’s invincible Bundesliga season
soccermatics is built for football x-y data.soccerPitch()soccerHeatmap()soccerPassmap()install.packages(c("remotes", "plotly"))
remotes::install_github("statsbomb/StatsBombR")
remotes::install_github("JoGall/soccermatics")
comp <- FreeCompetitions() |>
filter(competition_id == 9, season_id == 281)
matches <- FreeMatches(comp)
events <- free_allevents(matches, Parallel = FALSE) |>
allclean()Question: How effective was Florian Wirtz as a goal scorer in the title-clinching match?
shots_data <- title_events |>
dplyr::filter(
team.name == "Bayer Leverkusen",
player.name == "Florian Wirtz",
type.name == "Shot"
) |>
dplyr::mutate(
goal_flag = shot.outcome.name == "Goal"
)
soccermatics::soccerPitch(
theme = "grass",
title = "Florian Wirtz shot map",
subtitle = "vs Werder Bremen | 14 Apr 2024"
) +
ggplot2::geom_point(
data = shots_data,
aes(
x = location.x,
y = location.y,
size = shot.statsbomb_xg,
fill = goal_flag
),
shape = 21,
color = "pink",
stroke = 0.7,
alpha = 0.95
)Question: What did Leverkusen’s passing structure look like in their title-clinching game before their first substitution?
::::
Very fast path from raw coordinates to football-specific visuals.
Great package for teaching spatial thinking in sports analytics.
Works especially well with StatsBomb style event data.
plotly.soccerHeatmap(), soccerPassmap(), and package index.