Learn R Programming

soccermatics (version 0.9.0)

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(dat, lengthPitch = 105, widthPitch = 68, col = "black",
  arrow = c("none", "r", "l"), fillPitch = "white", colPitch = "grey60",
  grass = FALSE, lwd = 1, title = NULL, subtitle = NULL,
  legend = TRUE, x = "x", y = "y", id = NULL, plot = NULL)

Arguments

dat

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, colours from ColorBrewer's 'Paired' palette are used

arrow

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

fillPitch, colPitch

pitch background and line colour

grass

if TRUE, uses a more realistic pitch

lwd

player path thickness

title, subtitle

optional, adds title and subtitle to plot

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 'dat' contains multiple players)

plot

plot to add path to, if desired

Value

a ggplot object

Examples

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

# }

Run the code above in your browser using DataLab