Skip to contents
library(ussie)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

The goal of ussie is to help you work with European Football League data. It uses data from the englishsoccerdata package.

We can create a matches tibble using raw data from engsoccerdata

matches_italy <- uss_make_matches(engsoccerdata::italy, "Italy")

glimpse(matches_italy)
#> Rows: 25,404
#> Columns: 8
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 19…
#> $ date          <date> 1934-09-30, 1934-09-30, 1934-09-30, 1934-09-30, 1934-09…
#> $ home          <chr> "Lazio Roma", "Torino FC", "Sampierdarenese", "SSC Napol…
#> $ visitor       <chr> "US Livorno", "Unione Triestina", "Bologna FC", "US Ales…
#> $ goals_home    <int> 6, 3, 2, 0, 4, 0, 3, 1, 1, 1, 2, 4, 2, 2, 3, 2, 2, 2, 0,…
#> $ goals_visitor <int> 1, 1, 1, 1, 1, 2, 0, 2, 1, 1, 1, 0, 2, 1, 1, 0, 1, 1, 1,…

We can also create a matches tibble using ‘country’,

matches_italy <- uss_make_matches(engsoccerdata::italy, "Italy")

glimpse(matches_italy)
#> Rows: 25,404
#> Columns: 8
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 19…
#> $ date          <date> 1934-09-30, 1934-09-30, 1934-09-30, 1934-09-30, 1934-09…
#> $ home          <chr> "Lazio Roma", "Torino FC", "Sampierdarenese", "SSC Napol…
#> $ visitor       <chr> "US Livorno", "Unione Triestina", "Bologna FC", "US Ales…
#> $ goals_home    <int> 6, 3, 2, 0, 4, 0, 3, 1, 1, 1, 2, 4, 2, 2, 3, 2, 2, 2, 0,…
#> $ goals_visitor <int> 1, 1, 1, 1, 1, 2, 0, 2, 1, 1, 1, 0, 2, 1, 1, 0, 1, 1, 1,…

We can add filtering conditions:

uss_get_matches("italy", season == 1934) |> glimpse()
#> Rows: 240
#> Columns: 8
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 1934, 19…
#> $ date          <date> 1934-09-30, 1934-09-30, 1934-09-30, 1934-09-30, 1934-09…
#> $ home          <chr> "Lazio Roma", "Torino FC", "Sampierdarenese", "SSC Napol…
#> $ visitor       <chr> "US Livorno", "Unione Triestina", "Bologna FC", "US Ales…
#> $ goals_home    <int> 6, 3, 2, 0, 4, 0, 3, 1, 1, 1, 2, 4, 2, 2, 3, 2, 2, 2, 0,…
#> $ goals_visitor <int> 1, 1, 1, 1, 1, 2, 0, 2, 1, 1, 1, 0, 2, 1, 1, 0, 1, 1, 1,…

We can get the final results for seasons:

italy_season <-
  uss_get_matches("italy") |>
  uss_make_teams_matches() |>
  uss_make_seasons_final() |>
  glimpse()
#> Rows: 1,515
#> Columns: 12
#> Groups: country, tier, season [85]
#> $ country       <chr> "Italy", "Italy", "Italy", "Italy", "Italy", "Italy", "I…
#> $ tier          <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
#> $ season        <int> 1929, 1929, 1929, 1929, 1929, 1929, 1929, 1929, 1929, 19…
#> $ team          <chr> "AC Milan", "AS Roma", "Bologna FC", "Brescia Calcio", "…
#> $ date          <date> 1930-07-06, 1930-07-06, 1930-06-29, 1930-06-29, 1930-06…
#> $ matches       <int> 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, …
#> $ wins          <int> 18, 26, 14, 24, 18, 26, 30, 26, 18, 18, 22, 22, 22, 20, …
#> $ draws         <int> 6, 6, 10, 6, 4, 6, 2, 4, 10, 6, 8, 8, 10, 12, 6, 6, 14, …
#> $ losses        <int> 10, 2, 10, 4, 12, 2, 2, 4, 6, 10, 4, 4, 2, 2, 14, 8, 16,…
#> $ points        <int> 42, 58, 38, 54, 40, 58, 62, 56, 46, 42, 52, 52, 54, 52, …
#> $ goals_for     <int> 72, 120, 68, 70, 70, 82, 128, 74, 60, 58, 66, 80, 72, 78…
#> $ goals_against <int> 42, 24, 44, 40, 38, 32, 32, 26, 18, 42, 20, 32, 32, 20, …

We can take a look at effects of tiers on (wins - losses) :

leeds_norwich <-
  uss_get_matches("england") |>
  uss_make_teams_matches() |>
  dplyr::filter(team %in% c("Leeds United", "Norwich City")) |>
  dplyr::mutate(tier = as.factor(tier)) |>
  uss_make_seasons_final() |>
  dplyr::arrange(team, season)

uss_plot_seasons_tiers(leeds_norwich, wins - losses)