Draws the average x,y-positions of each player from one or both teams on a soccer pitch.
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"
)
a dataframe containing x,y-coordinates of player position and a player identifier variable
numeric, length and width of pitch in metres
character, fill colour of position points of team 1, team 2 (team 2 NULL
by default)
character, border colour of position points of team 1, team 2 (team 2 NULL
by default)
character, label text colour
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
.
flip x,y-coordinates of away team so attacking from right to left
type of label to draw, player names (name
), jersey numbers (number
), or none
add box around label text
shorten player names to display last name as label
numeric, size of position points
numeric, size of labels
optional, adds team direction of play arrow as right ('r'
) or left ('l'
)
draws a light
, dark
, grey
, or grass
coloured pitch
optional, adds title and subtitle to plot
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
.
names of variables containing x,y-coordinates, unique player ids, player names, and team names, respectively; name
and team
NULL by default
# NOT RUN {
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')")
# }
Run the code above in your browser using DataLab