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

Description Usage Arguments Value See Also Examples

View source: R/soccerPitchHalf.R

Description

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

Usage

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

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

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