Learn R Programming

soccermatics (version 0.9.0)

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, lengthPitch = 105, widthPitch = 68, xBins = 10,
  yBins = NULL, arrow = c("none", "r", "l"), colPitch = "black",
  colLow = "white", colHigh = "red", title = NULL, subtitle = NULL,
  x = "x", y = "y")

Arguments

df

dataframe containing x,y-coordinates of player position

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

arrow

optional, adds arrow showing team attack direction as right ('r') or left ('l')

colPitch

pitch line colour

colLow, colHigh

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

title, subtitle

optional, adds title and subtitle to plot

x, y

= name of variables containing x,y-coordinates

Value

a ggplot object of a heatmap on a soccer pitch.

Details

uses ggplot2::geom_bin2d to map 2D bin counts

See Also

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

Examples

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

# Heatmap of France defensive pressure locations w/ ~5x5m bins (pitchLength / 5 = 21, pitchWidth / 5 = 13.6) 
statsbomb %>%
  filter(type.name == "Pressure" & team.name == "France") %>% 
  soccerHeatmap(x = "location.x", y = "location.y", xBins = 21, yBins = 14,
               title = "France (vs Argentina, 30th June 2016)", 
               subtitle = "Defensive pressure heatmap")

# }

Run the code above in your browser using DataLab