soccerPath: Draw a path of player trajectory on a soccer pitch using any...

Description Usage Arguments Value Examples

View source: R/soccerPath.R

Description

Draws a path connecting consecutive x,y-coordinates of a player on a soccer pitch.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
soccerPath(
  df,
  lengthPitch = 105,
  widthPitch = 68,
  col = "black",
  arrow = c("none", "r", "l"),
  theme = c("light", "dark", "grey", "grass"),
  lwd = 1,
  title = NULL,
  subtitle = NULL,
  legend = FALSE,
  x = "x",
  y = "y",
  id = NULL,
  plot = NULL
)

Arguments

df

dataframe containing x,y-coordinates of player position

lengthPitch, widthPitch

length and width of pitch in metres

col

colour of path if no 'id' is provided; if an 'id' is present, uses ColorBrewer's 'Paired' palette by default

arrow

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

theme

draws a light, dark, grey, or grass coloured pitch

lwd

player path thickness

title, subtitle

adds title and subtitle to plot; NULL by default

legend

boolean, include legend

x, y

name of variables containing x,y-coordinates

id

character, the name of the column containing player identity (only required if 'df' contains multiple players)

plot

base plot to add path layer to; NULL by default

Value

a ggplot object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(dplyr)
data(tromso)

# draw path of Tromso #8 over first 3 minutes (1800 frames)
tromso %>% 
  filter(id == 8) %>% 
  top_n(1800) %>%
  soccerPath(col = "red", theme = "grass", arrow = "r")
  
# draw path of all Tromso players over first minute (600 frames)
tromso %>%
  group_by(id) %>%
  slice(1:1200) %>%
  soccerPath(id = "id", theme = "light")

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