Why this package?

  • soccermatics is built for football x-y data.
  • It gives soccer- specific plotting functions instead of making you draw the pitch from scratch.
  • Some of the most useful functions for a quick demo are:
    • soccerPitch()
    • soccerHeatmap()
    • soccerPassmap()
library(soccermatics)

events |>
  soccerTransform(method = "statsbomb") |>
  soccerPassmap(title = "Quick pass network")

Data for the demo

  • I used free StatsBomb data from Bayer Leverkusen’s 2023/24 Bundesliga title season.
  • StatsBomb is a premier sports data and analytics company renowned for providing the most detailed, high-quality event-level data in soccer and American football.
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()

Florian Wirtz Shot Map

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
  )

Passing map

Question: What did Leverkusen’s passing structure look like in their title-clinching game before their first substitution?

title_events |>
  dplyr::filter(
    team.name == "Bayer Leverkusen"
  ) |>
  soccermatics::soccerPassmap(
    minPass = 3,
    fill = "#c5161d",
    edgeCol = "grey35",
    edgeAlpha = 0.8,
    arrow = "r",
    theme = "light",
    title = "Bayer Leverkusen pass network before first substitution"
  )

::::

Why soccermatics?

Strengths

  • 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.

Limits

  • Installation is from GitHub, not CRAN (Comprehensive R Archive Network).
  • Some functions assume a football event schema already exists.
  • For interactivity, you’ll need to add another package such as plotly.

References

  • Jo Gall, soccermatics package documentation: soccerHeatmap(), soccerPassmap(), and package index.
  • Hudl StatsBomb, Free Data: Bayer Leverkusen’s Invincible Bundesliga Title Win.