Learn R Programming

soccermatics (version 0.8.4)

soccerSpokes: Draw spokes on a soccer pitch.

Description

Draws spokes showing the direction of all movements made in each sector of the pitch. Note: This function is prototypical and intended to eventually visualise pass and shot event data, but there are no open-source samples of such data available as yet.

Usage

soccerSpokes(df, xBins, lengthPitch = 105, widthPitch = 68,
  angleBins = 16, yBins = NULL, grass = FALSE, line_col = "black",
  lwd = 0.5, minLength = 0.6, minAlpha = 0.4, legend = TRUE,
  plot = NULL)

Arguments

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 'direction'.

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.

lengthPitch, widthPitch

numeric, length and width of pitch in metres.

angleBins

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

grass

if TRUE, draws pitch background in green and lines in white. If FALSE, draws pitch background in white and lines in black.

line_col

colour of pitch lines

lwd

thickness of arrow lines

minLength

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

minAlpha

numeric, minimum alpha of the arrow with the lowest number of events.

legend

if TRUE, adds legend showing relationship between arrow transparency and number of events

plot

optional, adds spokes to an existing ggplot object if provided

Value

a ggplot object of a heatmap on a soccer pitch.

See Also

soccerHeatmap for drawing a heatmap of player position, or soccerSpokes for summarising mean direction in each pitch sector

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)
# 10x10 x,y-bins, 8 angle-bins, grass pitch
soccerSpokes(id8, xBins = 5, angleBins = 8, grass = TRUE, minLength = 0.3, minAlpha = 0.7)
# 5x5 x,y-bins, 16 angle-bins, blank pitch w/ grey lines
soccerSpokes(id8, xBins = 5, angleBins = 16, line_col = "grey40")
# draw spokes over player heatmap
p <- soccerHeatmap(id8, xBins = 5)
soccerSpokes(id8, xBins = 5, plot = p)

# }

Run the code above in your browser using DataLab