Learn R Programming

soccermatics (version 0.8.4)

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

Description

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

Usage

soccerPath(df, id_var = NULL, lengthPitch = 105, widthPitch = 68,
  grass = FALSE, col = "black", lwd = 1, legend = TRUE, plot = NULL)

Arguments

df

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

id_var

character, the name of the column containing player identity. Only required if 'df' contains multiple players.

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.

col

colour of path if no 'id_var' is provided. If an 'id_var' is present, colours from ColorBrewer's 'Paired' palette are used.

lwd

thickness of path

Value

a ggplot object

Examples

Run this code
# NOT RUN {
data(tromso)
# draw path of player #8 over first 1200 frames
subset(tromso, id == 8)[1:1200,] %>%
  soccerPath(col = "red", grass = TRUE)
# draw path of all players over first 1200 frames
tromso %>%
  dplyr::group_by(id) %>%
  dplyr::slice(1:1200) %>%
  soccerPath("id")

# }

Run the code above in your browser using DataLab