Learn R Programming

soccermatics (version 0.9.0)

soccerSpokes: Visualise movement direction on a soccer pitch.

Description

Draws spokes showing the direction of x,y-movements made in each sector of the pitch.

Usage

soccerSpokes(plot, df, lengthPitch = 105, widthPitch = 68, xBins,
  yBins = NULL, angleBins = 16, lwd = 0.5, minLength = 0.6,
  minAlpha = 0.4, legend = TRUE, x = "x", y = "y", angle = "angle")

Arguments

plot

plot of soccer pitch returned by soccerPitch to add spokes to

df

dataframe containing x,y-coordinates of player position in columns named x and y and angular information (in radians, ranging between -pi and pi) in a column specified by argument angle

lengthPitch, widthPitch

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 no value for yBins is provided, it will take the value of xBins

angleBins

integer, the number of angle bins movement directions are divided up into. For example, a value of 4 clusters has direction vectors north, east, south and west

lwd

thickness of arrow lines

minLength

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

legend

if TRUE, adds legend for arrow thickness and transparency

x, y, angle

= name of variables containing x,y-coordinates and angular data

Value

a ggplot object

See Also

soccerPitch for drawing a heatmap of player position, soccerHeatmap for drawing a heatmap of player position

Examples

Run this code
# NOT RUN {
data(tromso_extra)
# resample movement dataset to plot 100 movement directions 
# (in absence of pass / shot event data as yet)
id8 <- tromso_extra %>%
  dplyr::filter(id == 8) %>%
  dplyr::sample_n(100)
# 5x5 x,y-bins, 16 angle-bins, blank pitch
soccerPitch(pitchLength, pitchWidth) %>% 
  soccerSpokes(id8, xBins = 5, angleBins = 16, minLength = 0.4)
# 10x10 x,y-bins, 8 angle-bins, grass pitch
soccerPitch(pitchLength, pitchWidth, grass = T) %>% 
  soccerSpokes(id8, xBins = 10, angleBins = 8, minLength = 0.2, lwd = 1)
# draw spokes over player heatmap w/ 5x5 x,y-bins, 8 angle-bins
soccerHeatmap(id8, xBins = 5) %>% 
  soccerSpokes(id8, xBins = 5, angleBins = 8, lwd = 1)

# }

Run the code above in your browser using DataLab