soccerPitch: Plot a full soccer pitch

Description Usage Arguments Value Examples

View source: R/soccerPitch.R

Description

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

Usage

1
2
3
4
5
6
7
8
9
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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)

JoGall/soccermatics documentation built on Aug. 12, 2021, 1:20 p.m.