soccerSpokes: Draw spokes of passing direction on a soccer pitch

Description Usage Arguments Value See Also Examples

View source: R/soccerSpokes.R

Description

Multiple arrows to show the distribution of pass angle and distance in zones of the pitch; similar to a radar plot but grouped by pitch location rather than player

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
soccerSpokes(
  df,
  lengthPitch = 105,
  widthPitch = 68,
  xBins = 5,
  yBins = NULL,
  angleBins = 8,
  x = "x",
  y = "y",
  angle = "angle",
  minLength = 0.6,
  minAlpha = 0.5,
  minWidth = 0.5,
  col = "black",
  legend = TRUE,
  arrow = c("none", "r", "l"),
  title = NULL,
  subtitle = NULL,
  theme = c("light", "dark", "grey", "grass"),
  plot = NULL
)

Arguments

df

a dataframe of event data containing fields of start x,y-coordinates, pass distance, and pass angle

lengthPitch, widthPitch

numeric, length and width of pitch in metres

xBins, yBins

integer, the number of horizontal (length-wise) and vertical (width-wise) bins the soccer pitch is to be divided up into; if yBins is NULL (default), it will take the value of xBins

angleBins

integer, the number of arrows to draw in each zone of the pitch; for example, a value of 4 clusters has direction vectors up, down, left, and right

x, y, angle

names of variables containing pass start x,y-coordinates and angle

minLength

numeric, ratio between size of shortest arrow and longest arrow depending on number of events

minAlpha, minWidth

numeric, minimum alpha and line width of arrows drawn

col

colour of arrows

legend

if TRUE, adds legend for arrow transparency

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

plot

base plot to add path layer to; NULL by default

Value

a ggplot object of a heatmap on a soccer pitch

See Also

soccerHeatmap for drawing a heatmap of player position, or soccerFlow for drawing a single arrow for pass distance and angle per pitch zone.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(dplyr)
data(statsbomb)

# transform x,y-coords, filter only France pass events,
# draw flow field showing mean angle, distance of passes per pitch zone
statsbomb %>% 
  soccerTransform(method = 'statsbomb') %>% 
  filter(team.name == "France" & type.name == "Pass") %>% 
  soccerSpokes(xBins=7, yBins=5, angleBins=12, legend=FALSE)
                   
# transform x,y-coords, standarise column names,
# filter only France pass events
my_df <- statsbomb %>%
 soccerTransform(method = 'statsbomb') %>%
 soccerStandardiseCols(method = 'statsbomb') %>%
  filter(team_name == "France" & event_name == "Pass")
  
# overlay flow field onto heatmap showing proportion of team passes per pitch zone
soccerHeatmap(my_df, xBins=7, yBins=5,
              title = "France passing radar") %>%
  soccerSpokes(my_df, xBins=7, yBins=5, angleBins=8, legend=FALSE, plot = .)
           

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