soccerHeatmap: Draw a heatmap on a soccer pitch using any event or tracking...

Description Usage Arguments Details Value Examples

View source: R/soccerHeatmap.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
soccerHeatmap(
  df,
  lengthPitch = 105,
  widthPitch = 68,
  xBins = 10,
  yBins = NULL,
  kde = FALSE,
  arrow = c("none", "r", "l"),
  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.

kde

use kernel density estimates for a smoother heatmap; FALSE by default

arrow

adds team direction of play arrow as right ('r') or left ('l'); 'none' by default

colLow, colHigh

character, colours for the low and high ends of the heatmap gradient; white and red respectively by default

title, subtitle

adds title and subtitle to plot; NULL by default

x, y

name of variables containing x,y-coordinates

Details

uses ggplot2::geom_bin2d to map 2D bin counts

Value

a ggplot object of a heatmap on a soccer pitch.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(dplyr)

# tracking data heatmap with 21x5 zones(~5x5m)
data(tromso)
tromso %>% 
  filter(id == 8) %>% 
  soccerHeatmap(xBins = 10)

# transform x,y-coords, filter only France pressure events,
# heatmap with 6x3 zones
data(statsbomb)
statsbomb %>%
  soccerTransform(method='statsbomb') %>% 
  filter(type.name == "Pressure" & team.name == "France") %>% 
  soccerHeatmap(x = "location.x", y = "location.y",
                xBins = 6, yBins = 3, arrow = "r", 
                title = "France (vs Argentina, 30th June 2016)", 
                subtitle = "Defensive pressure heatmap")

# transform x,y-coords, standardise column names,
# filter player defensive actions, plot kernel density estimate heatmap
statsbomb %>%
  soccerTransform(method='statsbomb') %>% 
  soccerStandardiseCols() %>% 
  filter(event_name %in% c("Duel", "Interception", "Clearance", "Block") &
         player_name == "Samuel Yves Umtiti") %>%
  soccerHeatmap(kde = TRUE, arrow = "r",
                title = "Umtiti (vs Argentina, 30th June 2016)",
                subtitle = "Defensive actions heatmap")
                

JoGall/soccermatics documentation built on Aug. 12, 2021, 1:20 p.m.