Learn R Programming

soccermatics (version 0.8.4)

soccerHeatmap: Draw a heatmap on a soccer pitch.

Description

Draws a heatmap showing player position frequency in each area of the pitch and adds soccer pitch outlines.

Usage

soccerHeatmap(df, xBins, lengthPitch = 105, widthPitch = 68, yBins = NULL,
  colLow = "white", colHigh = "red")

Arguments

df

dataframe containing x,y-coordinates of player position in columns named 'x' and 'y'.

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.

colLow, colHigh

character, colours for the low and high ends of the heatmap gradient.

Value

a ggplot object of a heatmap on a soccer pitch.

Details

uses ggplot2::geom_bin2d to map 2D bin counts

See Also

soccerPitchBG for a background soccer pitch for the purpose of drawing position maps, player trajectories, etc..

Examples

Run this code
# NOT RUN {
data(tromso)
# simple heatmap of player #9's position
soccerHeatmap(subset(tromso, id == 8), xBins = 10)

# draw heatmap with approximately 5m x 5m bins (pitchLength / 5 = 21, pitchWidth / 5 = 13.6)
soccerHeatmap(subset(tromso, id == 8), xBins = 21, yBins = 14)

# }

Run the code above in your browser using DataLab