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 engsoccerdata 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 a country
:
get_matches_italy <- uss_get_matches("italy")
glimpse(get_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_seasons <-
get_matches_italy |>
uss_make_teams_matches() |>
uss_make_seasons_final() |>
glimpse()
#> Rows: 1,516
#> 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-07-06, 1930-07-06, 1930-07…
#> $ matches <int> 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, …
#> $ wins <int> 11, 15, 14, 13, 11, 20, 22, 19, 10, 11, 12, 12, 14, 16, …
#> $ draws <int> 10, 6, 8, 7, 4, 8, 6, 7, 8, 8, 6, 9, 9, 7, 6, 8, 8, 5, 7…
#> $ losses <int> 13, 13, 12, 14, 19, 6, 6, 8, 16, 15, 16, 13, 11, 11, 17,…
#> $ points <int> 32, 36, 36, 33, 26, 48, 50, 45, 28, 30, 30, 33, 37, 39, …
#> $ goals_for <int> 53, 73, 56, 45, 52, 63, 85, 56, 49, 48, 46, 52, 61, 52, …
#> $ goals_against <int> 48, 52, 46, 56, 78, 39, 38, 31, 50, 55, 64, 60, 51, 31, …
We can look at the effect 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)