Learn R Programming

soccermatics (version 0.9.5)

soccerPitch: Plot a full soccer pitch

Description

Draws a soccer pitch as a ggplot object for the purpose of adding layers such as player positions, player trajectories, etc..

Usage

soccerPitch(
  lengthPitch = 105,
  widthPitch = 68,
  arrow = c("none", "r", "l"),
  title = NULL,
  subtitle = NULL,
  theme = c("light", "dark", "grey", "grass"),
  data = NULL
)

Arguments

lengthPitch, widthPitch

length and width of pitch in metres

arrow

adds team direction of play arrow as right ('r') or left ('l'); 'none' by default

title, subtitle

adds title and subtitle to plot; NULL by default

theme

palette of pitch background and lines, either light (default), dark, grey, or grass

data

a default dataset for plotting in subsequent layers; NULL by default

Value

a ggplot object

Examples

Run this code
# NOT RUN {
library(ggplot2)
data(statsbomb)

# transform Statsbomb coordinates to metre units for plotting
my_df <- soccerTransform(statsbomb, method = "statsbomb")

# filter events of interest (France defensive pressure events vs. Argentina)
my_df <- my_df %>% 
  dplyr::filter(team.name == "France" & type.name == "Pressure")

# add custom layers to soccerPitch base
soccerPitch(data = my_df,
            arrow = "r", theme = "grass", 
            title = "France (vs. Argentina)", 
            subtitle = "Pressure events") + 
  geom_point(aes(x = location.x, y = location.y), 
             col = "blue", alpha = 0.5)

# }

Run the code above in your browser using DataLab