soccerxGTimeline: Draw a timeline showing cumulative expected goals (xG) over...

Description Usage Arguments Value Examples

View source: R/soccerxGTimeline.R

Description

Draw a timeline showing cumulative expected goals (xG, excluding penalties and own goals) by two teams over the course of a match, as well as plotting the scoreline and goalscorer at goal events. Currently only works with StatsBomb data but compatability with other (non-StatsBomb) shot data will be added soon.

Usage

1
2
3
4
5
6
7
8
soccerxGTimeline(
  df,
  homeCol = "red",
  awayCol = "blue",
  adj = TRUE,
  labels = TRUE,
  y_buffer = 0.3
)

Arguments

df

a dataframe containing StatsBomb data from one full match

homeCol, awayCol

colours of the home and away team, respectively

adj

adjust xG using conditional probability to account for multiple shots per possession

labels

include scoreline and goalscorer labels for goals

y_buffer

vertical space to add at the top of the y-axis (a quick and dirty way to ensure text annotations are not cropped).

Value

a ggplot object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
library(dplyr)
data(statsbomb)

# xG timeline of France vs. Argentina
# w/ goalscorer labels, adjusted xG data
statsbomb %>%
  soccerxGTimeline(homeCol = "blue", awayCol = "lightblue", y_buffer = 0.4)

# no goalscorer labels, raw xG data
statsbomb %>%
  soccerxGTimeline(homeCol = "blue", awayCol = "lightblue", adj = FALSE)

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