soccerFlow: Draw a flow field of passing direction on a soccer pitch

Description Usage Arguments Value See Also Examples

View source: R/soccerFlow.R

Description

A flow field to show the mean angle and distance of passes in zones of the pitch

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
soccerFlow(
  df,
  lengthPitch = 105,
  widthPitch = 68,
  xBins = 5,
  yBins = NULL,
  x = "x",
  y = "y",
  angle = "angle",
  distance = "distance",
  col = "black",
  lwd = 0.5,
  arrow = c("none", "r", "l"),
  title = NULL,
  subtitle = NULL,
  theme = c("light", "dark", "grey", "grass"),
  plot = NULL
)

Arguments

df

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

x, y, angle, distance

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

col

colour of arrows

lwd

thickness of arrow segments

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 soccerSpokes for drawing spokes to show all directions in each area of the pitch.

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") %>% 
  soccerFlow(xBins=7, yBins=5,
             x="location.x", y="location.y", angle="pass.angle", distance="pass.length")
                   
# 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) %>%
  soccerFlow(my_df, xBins=7, yBins=5, plot = .)
           

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