soccerPositionMap: Plot average player position using any event or tracking data

Description Usage Arguments Examples

View source: R/soccerPositionMap.R

Description

Draws the average x,y-positions of each player from one or both teams on a soccer pitch.

Usage

 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
soccerPositionMap(
  df,
  lengthPitch = 105,
  widthPitch = 68,
  fill1 = "red",
  col1 = NULL,
  fill2 = "blue",
  col2 = NULL,
  labelCol = "black",
  homeTeam = NULL,
  flipAwayTeam = TRUE,
  label = c("name", "number", "none"),
  labelBox = TRUE,
  shortNames = TRUE,
  nodeSize = 5,
  labelSize = 4,
  arrow = c("none", "r", "l"),
  theme = c("light", "dark", "grey", "grass"),
  title = NULL,
  subtitle = NULL,
  source = c("manual", "statsbomb"),
  x = "x",
  y = "y",
  id = "player_id",
  name = "player_name",
  team = "team_name"
)

Arguments

df

a dataframe containing x,y-coordinates of player position and a player identifier variable

lengthPitch, widthPitch

numeric, length and width of pitch in metres

fill1, fill2

character, fill colour of position points of team 1, team 2 (team 2 NULL by default)

col1, col2

character, border colour of position points of team 1, team 2 (team 2 NULL by default)

labelCol

character, label text colour

homeTeam

if df contains two teams, the name of the home team to be displayed on the left hand side of the pitch (i.e. attacking from left to right). If NULL, infers home team as the team of the first event in df.

flipAwayTeam

flip x,y-coordinates of away team so attacking from right to left

label

type of label to draw, player names (name), jersey numbers (number), or none

labelBox

add box around label text

shortNames

shorten player names to display last name as label

nodeSize

numeric, size of position points

labelSize

numeric, size of labels

arrow

optional, adds team direction of play arrow as right ('r') or left ('l')

theme

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

title, subtitle

optional, adds title and subtitle to plot

source

if statsbomb, uses StatsBomb definitions of required variable names (i.e. 'location.x', 'location.y', 'player.id', 'team.name'); if manual (default), respects variable names defined in function arguments x, y, id, name, and team.

x, y, id, name, team

names of variables containing x,y-coordinates, unique player ids, player names, and team names, respectively; name and team NULL by default

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
31
32
33
34
library(dplyr)
data(statsbomb)

# average player position from tracking data for one team
# w/ jersey numbers labelled
data(tromso)
tromso %>%
  soccerPositionMap(label = "number", id ="id",
                    labelCol = "white", nodeSize = 8,
                    arrow = "r", theme = "grass",
                    title = "Tromso IL (vs. Stromsgodset, 3rd Nov 2013)",
                    subtitle = "Average player position (1' - 16')")

# transform x,y-coords, standarise column names,
# average pass position for one team using 'statsbomb' method
# w/ player name as labels
statsbomb %>%
  soccerTransform(method='statsbomb') %>%
  filter(type.name == "Pass" & team.name == "France" & period == 1) %>%
  soccerPositionMap(source = "statsbomb",
                    fill1 = "blue", arrow = "r", theme = "light",
                    title = "France (vs Argentina, 30th June 2018)",
                    subtitle = "Average pass position (1' - 45')")
                 
# transform x,y-coords, standarise column names,
# average pass position for two teams using 'manual' method
# w/ player names labelled
statsbomb %>%
  soccerTransform(method='statsbomb') %>%
  soccerStandardiseCols(method='statsbomb') %>% 
  filter(event_name == "Pass" & period == 1) %>%
  soccerPositionMap(fill1 = "lightblue", fill2 = "blue",
                    title = "Argentina vs France, 30th June 2018",
                    subtitle = "Average pass position (1' - 45')")

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