Learn R Programming

soccermatics (version 0.8.4)

soccerFlow: Draw a flow field on a soccer pitch.

Description

Draws a flow field showing the mean direction of movement made in each sector of the pitch and adds pitch outlines. 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

soccerFlow(df, xBins, yBins = NULL, lengthPitch = 105, widthPitch = 68,
  grass = FALSE, line_col = "black", lwd = 1, 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.

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.

plot

optional, adds wagon wheels 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 drawing spokes to show all directions in each area of the pitch.

Examples

Run this code
# NOT RUN {
data(tromso_extra)
# draw flow field showing mean direction of player #8's movement
soccerFlow(subset(tromso_extra, id == 8), xBins = 5, grass = TRUE)
# draw flow field over player heatmap
p <- soccerHeatmap(subset(tromso_extra, id == 8), xBins = 5)
soccerFlow(subset(tromso_extra, id == 8), xBins = 5, plot = p)

# }

Run the code above in your browser using DataLab