Learn R Programming

soccermatics (version 0.9.5)

soccerPitchHalf: Draws a vertical half soccer pitch for the purpose of plotting shotmaps

Description

Adds soccer pitch outlines (with transparent fill) to an existing ggplot object (e.g. heatmaps, passing maps, etc..)

Usage

soccerPitchHalf(
  lengthPitch = 105,
  widthPitch = 68,
  arrow = c("none", "r", "l"),
  theme = c("light", "dark", "grey", "grass"),
  title = NULL,
  subtitle = NULL,
  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

theme

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

title, subtitle

adds title and subtitle to plot; NULL by default

data

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

Value

a ggplot object

See Also

soccerShotmap for plotting a shotmap on a half pitch for a single player or soccerPitch for drawing a full size soccer pitch

Examples

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

# normalise data, get non-penalty shots for France, 
# add boolean variable 'goal' for plotting
my_df <- statsbomb %>%
  soccerTransform(method = 'statsbomb') %>% 
  filter(team.name == "France" &
         type.name == "Shot" &
         shot.type.name != 'penalty') %>%
  mutate(goal = as.factor(if_else(shot.outcome.name == "Goal", 1, 0)))
  
soccerPitchHalf(data = my_df, theme = 'light') +
  geom_point(aes(x = location.y, y = location.x,
                 size = shot.statsbomb_xg, colour = goal),
             alpha = 0.7)
            
# }

Run the code above in your browser using DataLab