Learn R Programming

soccermatics (version 0.9.0)

soccerPassmap: Draw a passing network on a pitch from StatsBomb data

Description

Draw an undirected passing network of completed passes on pitch from StatsBomb data. Nodes are scaled by number of successful passes; edge width is scaled by number of successful passes between each node pair. Only passes made until first substition shown (ability to specify custom minutes will be added soon). Total number of passes attempted and percentage of completed passes shown. Compatability with other (non-StatsBomb) shot data will be added soon.

Usage

soccerPassmap(df, lengthPitch = 105, widthPitch = 68, minPass = 3,
  fill = "red", col = "black", edgeCol = "black", edgeAlpha = 0.6,
  maxNodeSize = 30, maxEdgeSize = 30, labelSize = 4, grass = FALSE,
  arrow = c("none", "r", "l"), title = NULL, x = "location.x",
  y = "location.y", id = "player.id", label = "player.name",
  shortNames = TRUE)

Arguments

df

dataframe containing x,y-coordinates of player passes

lengthPitch, widthPitch

numeric, length and width of pitch in metres

fill, col

fill and (border) colour of nodes

edgeCol, edgeAlpha

colour and transparency of edge lines

maxNodeSize

maximum size of nodes

maxEdgeSize

maximum width of edge lines

labelSize

size of player name labels

grass

if TRUE, uses a more realistic pitch

arrow

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

title

adds custom title to plot. Defaults to team name.

x, y

= name of variables containing x,y-coordinates. Defaults to 'location.x','location.y' for StatsBomb data

id

character, the name of the column containing unique player identity. Defaults to 'player.id' for StatsBomb data

label

character, the name of the column containing player name for labels. Defaults to 'player.name' for StatsBomb data

Value

a ggplot object

See Also

soccerPitchBG for drawing a soccer pitch as foreground over an existing ggplot object

Examples

Run this code
# NOT RUN {
# France vs. Argentina, minimum of three passes
library(dplyr)
library(soccermatics)

# Argentina pass map until first substituton with transparent edges
statsbomb %>% 
  filter(team.name == "Argentina") %>% 
  soccerPassmap(fill = "lightblue", arrow = "r",
                title = "Argentina (vs France, 30th June 2018)")

# France pass map until first substituton with opaque edges
statsbomb %>% 
  filter(team.name == "France") %>% 
  soccerPassmap(fill = "blue", minPass = 3,
                maxEdgeSize = 30, edgeCol = "grey40", edgeAlpha = 1,
                title = "France (vs Argentina, 30th June 2018)")
# }

Run the code above in your browser using DataLab