knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  message=FALSE,
  warning=FALSE
)

Overview

This package is designed to allow users to extract various world football results and player statistics from the following popular football (soccer) data sites:

Installation

As at 2024-06-29, we are no longer including instructions to install from CRAN. The version pushed to CRAN is very much out of date, and with very regular updates to this library, we advise installing from GitHub only.

You can install the released version of worldfootballR from GitHub with:

# install.packages("devtools")
devtools::install_github("JaseZiv/worldfootballR")
library(worldfootballR)

Usage

Package vignettes have been built to help you get started with the package.

This vignette will cover the functions to extract data from understat.com


Understat Helper Functions

Team Names

To get a list of all available teams names team selected league, use the understat_avalaible_teams() function.

You can pass the results of the understat_avalaible_teams() function execution to the understat_team_meta() function.

team_names <- understat_team_meta(team_name = understat_avalaible_teams(league = 'EPL'))

Team URLs

To get a list of all season team URLs for selected teams, use the understat_team_meta() function (note, to get team names, it might be advisable to look at Understat.com's spelling of the team names and pass that through to the function):

team_urls <- understat_team_meta(team_name = c("Liverpool", "Manchester City"))

League Season-Level Data

This section will cover the functions to aid in the extraction of season league statistics from Understat.

The following leagues are currently supported by Understat (these values can be passed in to the league arguments of most understat_ functions):

Match Results

To be able to extract match results from Understat, which not only have results and expected goals, but they also provide a probability of a team winning.

To extract the data, use the understat_league_match_results() function:

# to get the EPL results:
epl_results <- understat_league_match_results(league = "EPL", season_start_year = 2020)
dplyr::glimpse(epl_results)

Season Shooting locations

To get shooting locations for a whole season in supported leagues, use the understat_league_season_shots() function:

ligue1_shot_location <- understat_league_season_shots(league = "Ligue 1", season_start_year = 2020)

Match-Level Data

The following sections outlines the functions available to extract data at the per-match level

Match Shooting Locations

To get shooting locations for an individual match, use the understat_match_shots() function:

wba_liv_shots <- understat_match_shots(match_url = "https://understat.com/match/14789")
dplyr::glimpse(wba_liv_shots)

Match Stats

To get the data from the stats table for an individual match, use the understat_match_stats() function:

wba_liv_stats <- understat_match_stats(match_url = "https://understat.com/match/14789")
dplyr::glimpse(wba_liv_stats)

Match Players

To get the data for player in an individual match, use the understat_match_players() function:

wba_liv_players <- understat_match_players(match_url = "https://understat.com/match/14789")
dplyr::glimpse(wba_liv_players)

Team Data

This section will cover off the functions to get team-level data from Transfermarkt.

Team Shooting Locations

To get all shots taken and conceded by a team during a season, use the understat_team_season_shots() function:

# for one team:
man_city_shots <- understat_team_season_shots(team_url = "https://understat.com/team/Manchester_City/2020")
dplyr::glimpse(man_city_shots)

Team Stat Breakdowns

To get a more granular breakdown of team shooting data for whole seasons, the understat_team_stats_breakdown() function can be used. This functions returns a breakdown of team shooting data based on the following groupings:

#----- Can get data for single teams at a time: -----#
team_breakdown <- understat_team_stats_breakdown(team_urls = "https://understat.com/team/Liverpool/2020")
dplyr::glimpse(team_breakdown)

#----- Or for multiple teams: -----#
# team_urls <- c("https://understat.com/team/Liverpool/2020",
#                "https://understat.com/team/Manchester_City/2020")
# team_breakdown <- understat_team_stats_breakdown(team_urls = team_urls)

Player Data

This section will cover the functions available to aid in the extraction of player data.

Player Shooting Locations

To get shooting locations for all games a player has participated in (for as long as Understat has data for), use the understat_player_shots() function:

raheem_sterling_shots <- understat_player_shots(player_url = "https://understat.com/player/618")
dplyr::glimpse(raheem_sterling_shots)

Team Player Season Stats

To get stats for all players of selected teams, run the understat_team_players_stats() function.

Note: Team URLs cal be extracted using understat_team_meta().

team_players <- understat_team_players_stats(team_url = c("https://understat.com/team/Liverpool/2020", "https://understat.com/team/Manchester_City/2020"))
dplyr::glimpse(team_players)



JaseZiv/worldfootballR documentation built on April 5, 2025, 5:06 p.m.