vignettes/extract-fotmob-data.Rmd
extract-fotmob-data.Rmd
This package is designed to allow users to extract various world football results and player statistics from the following popular football (soccer) data sites:
You can install the CRAN version of worldfootballR
with:
install.packages("worldfootballR")
You can install the released version of worldfootballR
from GitHub with:
# install.packages("devtools")
devtools::install_github("JaseZiv/worldfootballR")
Package vignettes have been built to help you get started with the package.
This vignette will cover the functions to extract data from fotmob.com
fotmob has data for just about every league that you can think of, including all of the Big 5 leagues.
Use fotmob_get_season_stats
to retrieve values for a specified stat, season, and league. See the docs for the function for a complete list of stat_name
s. Note that some stats are only available for either team or player, and that some names are different for teams and players (e.g. "Expected goals"
for "team"
and "Expected goals (xG)"
for "player"
).
epl_team_xg_2021 <- fotmob_get_season_stats(
country = "ENG",
league_name = "Premier League",
season_name = "2020/2021",
stat_name = "Expected goals",
team_or_player = "team"
)
epl_team_xg_2021 %>%
dplyr::select(
league_id,
league_name,
season_id,
season_name,
team_id,
team_name = participant_name,
matches_played,
xg = stat_value,
g = sub_stat_value
) %>%
dplyr::glimpse()
#> Rows: 20
#> Columns: 9
#> $ league_id <int> 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,…
#> $ league_name <chr> "Premier League", "Premier League", "Premier League", "…
#> $ season_id <chr> "15382", "15382", "15382", "15382", "15382", "15382", "…
#> $ season_name <chr> "2020/2021", "2020/2021", "2020/2021", "2020/2021", "20…
#> $ team_id <int> 8456, 8650, 8455, 10260, 8654, 8463, 8197, 8586, 10252,…
#> $ team_name <chr> "Manchester City", "Liverpool", "Chelsea", "Manchester …
#> $ matches_played <int> 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,…
#> $ xg <dbl> 68.9, 68.4, 62.9, 60.9, 56.7, 56.4, 56.1, 53.8, 53.8, 5…
#> $ g <dbl> 83, 68, 58, 73, 62, 62, 68, 68, 55, 55, 40, 47, 46, 47,…
If you know the league_id
, you can use it instead of passing in values for country
and league_name
.
fotmob_get_season_stats(
league_id = 47,
season_name = "2020/2021",
stat_name = "Expected goals",
team_or_player = "team"
)
#> # A tibble: 20 × 20
#> country league_name league_id season_name season_id stat_league_name
#> <chr> <chr> <int> <chr> <chr> <chr>
#> 1 ENG Premier League 47 2020/2021 15382 Premier League
#> 2 ENG Premier League 47 2020/2021 15382 Premier League
#> 3 ENG Premier League 47 2020/2021 15382 Premier League
#> 4 ENG Premier League 47 2020/2021 15382 Premier League
#> 5 ENG Premier League 47 2020/2021 15382 Premier League
#> 6 ENG Premier League 47 2020/2021 15382 Premier League
#> 7 ENG Premier League 47 2020/2021 15382 Premier League
#> 8 ENG Premier League 47 2020/2021 15382 Premier League
#> 9 ENG Premier League 47 2020/2021 15382 Premier League
#> 10 ENG Premier League 47 2020/2021 15382 Premier League
#> 11 ENG Premier League 47 2020/2021 15382 Premier League
#> 12 ENG Premier League 47 2020/2021 15382 Premier League
#> 13 ENG Premier League 47 2020/2021 15382 Premier League
#> 14 ENG Premier League 47 2020/2021 15382 Premier League
#> 15 ENG Premier League 47 2020/2021 15382 Premier League
#> 16 ENG Premier League 47 2020/2021 15382 Premier League
#> 17 ENG Premier League 47 2020/2021 15382 Premier League
#> 18 ENG Premier League 47 2020/2021 15382 Premier League
#> 19 ENG Premier League 47 2020/2021 15382 Premier League
#> 20 ENG Premier League 47 2020/2021 15382 Premier League
#> # … with 14 more variables: stat_name <chr>, stat <chr>,
#> # participant_name <chr>, particiant_id <int>, team_id <int>,
#> # team_color <chr>, stat_value <dbl>, sub_stat_value <dbl>,
#> # minutes_played <int>, matches_played <int>, stat_value_count <int>,
#> # rank <int>, participant_country_code <chr>, team_name <lgl>
You can retrieve data for multiple leagues, seasons, or stat types at the same time.
team_xgs_2021 <- fotmob_get_season_stats(
country = c("ITA", "ESP"),
league_name = c("Serie A", "LaLiga"),
season_name = c("2020/2021", "2021/2022"),
stat_name = c("Expected goals", "xG conceded"),
team_or_player = "team"
)
## 2 leagues x 20 teams x 2 seasons x 2 stats = 160 rows
team_xgs_2021 %>% nrow()
#> [1] 160
International tournament data can be retrieved.
fotmob_get_season_stats(
league_id = 42,
season_name = "2020/2021",
stat_name = "Expected goals",
team_or_player = "team"
)
#> # A tibble: 32 × 20
#> country league_name league_id season_name season_id stat_league_name
#> <chr> <chr> <int> <chr> <chr> <chr>
#> 1 INT Champions League 42 2020/2021 15237 Champions League
#> 2 INT Champions League 42 2020/2021 15237 Champions League
#> 3 INT Champions League 42 2020/2021 15237 Champions League
#> 4 INT Champions League 42 2020/2021 15237 Champions League
#> 5 INT Champions League 42 2020/2021 15237 Champions League
#> 6 INT Champions League 42 2020/2021 15237 Champions League
#> 7 INT Champions League 42 2020/2021 15237 Champions League
#> 8 INT Champions League 42 2020/2021 15237 Champions League
#> 9 INT Champions League 42 2020/2021 15237 Champions League
#> 10 INT Champions League 42 2020/2021 15237 Champions League
#> # … with 22 more rows, and 14 more variables: stat_name <chr>, stat <chr>,
#> # participant_name <chr>, particiant_id <int>, team_id <int>,
#> # team_color <chr>, stat_value <dbl>, sub_stat_value <dbl>,
#> # minutes_played <int>, matches_played <int>, stat_value_count <int>,
#> # rank <int>, participant_country_code <chr>, team_name <lgl>
You can potentially get cup data for leagues in the future, although at this time Fotmob does not have this data for most leagues, seasons, or stats.
## Not run to avoid error.
fotmob_get_season_stats(
league_id = 47,
season_name = "2020/2021",
stat_name = "Expected goals",
team_or_player = "team",
stat_league_name = "FA Cup"
)
At this time, only one team_or_player
can be retrieved at a time.
You can also use fotmob_get_season_stats
to retrieve stats for players.
epl_player_xg_2021 <- fotmob_get_season_stats(
country = "ENG",
league_name = "Premier League",
season = "2020/2021",
stat_name = "Expected goals (xG)",
team_or_player = "player"
)
epl_player_xg_2021 %>%
dplyr::select(
league_id,
league_name,
season_id,
season_name,
team_id,
## NOTE: particiant_id is a typo on behalf of fotmob! We leave it as is.
player_id = particiant_id,
player_name = participant_name,
minutes_played,
matches_played,
xg = stat_value,
g = sub_stat_value
) %>%
dplyr::glimpse()
#> Rows: 433
#> Columns: 11
#> $ league_id <int> 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,…
#> $ league_name <chr> "Premier League", "Premier League", "Premier League", "…
#> $ season_id <chr> "15382", "15382", "15382", "15382", "15382", "15382", "…
#> $ season_name <chr> "2020/2021", "2020/2021", "2020/2021", "2020/2021", "20…
#> $ team_id <int> 8586, 8197, 8650, 8463, 8668, 10260, 10252, 8650, 8654,…
#> $ player_id <int> 194165, 286119, 292462, 302241, 612150, 422685, 540088,…
#> $ player_name <chr> "Harry Kane", "Jamie Vardy", "Mohamed Salah", "Patrick …
#> $ minutes_played <int> 3085, 2844, 3079, 3062, 2874, 3105, 3329, 2810, 1983, 2…
#> $ matches_played <int> 35, 34, 37, 38, 33, 37, 37, 35, 26, 33, 33, 26, 31, 36,…
#> $ xg <dbl> 20.2, 19.9, 19.3, 18.3, 16.3, 16.1, 14.6, 14.2, 13.6, 1…
#> $ g <dbl> 23, 15, 22, 17, 16, 18, 14, 11, 10, 8, 12, 12, 13, 9, 6…
Matches for one or multiple leagues can be retrieved with fotmob_get_league_matches
. Currently only the current season’s matches can be retrieved.
league_matches <- fotmob_get_league_matches(
country = c("ENG", "ESP" ),
league_name = c("Premier League", "LaLiga")
)
league_matches_unnested <- league_matches %>%
dplyr::select(match_id = id, home, away) %>%
tidyr::unnest_wider(c(home, away), names_sep = "_")
dplyr::glimpse(league_matches_unnested)
#> Rows: 760
#> Columns: 7
#> $ match_id <chr> "3609929", "3609934", "3609930", "3609931", "3609932", "360…
#> $ home_id <chr> "9937", "10260", "8191", "8455", "8668", "8197", "9817", "9…
#> $ home_name <chr> "Brentford", "Man United", "Burnley", "Chelsea", "Everton",…
#> $ home_score <int> 2, 5, 1, 3, 3, 1, 3, 0, 2, 1, 2, 2, 0, 2, 5, 2, 1, 0, 0, 4,…
#> $ away_id <chr> "9825", "8463", "10204", "9826", "8466", "8602", "10252", "…
#> $ away_name <chr> "Arsenal", "Leeds", "Brighton", "Crystal Palace", "Southamp…
#> $ away_score <int> 0, 1, 2, 0, 1, 0, 2, 3, 4, 0, 0, 0, 0, 2, 0, 0, 1, 1, 2, 1,…
fotmob also lists data for all leagues by date. Use fotmob_get_matches_by_date
to select matches occurring on specific day(s) and filter down to the league(s) that you care about.
results <- fotmob_get_matches_by_date(date = c("20210925", "20210926"))
dplyr::glimpse(results)
#> Rows: 268
#> Columns: 12
#> $ ccode <chr> "USA", "ENG", "ESP", "ITA", "GER", "FRA", "USA", "U…
#> $ id <int> 872390, 47, 87, 55, 54, 53, 8972, 873262, 872547, 8…
#> $ primary_id <int> 130, 47, 87, 55, 54, 53, 8972, 9134, 9296, 48, 230,…
#> $ name <chr> "Major League Soccer", "Premier League", "LaLiga", …
#> $ matches <list> [<data.frame[10 x 11]>], [<data.frame[7 x 11]>], […
#> $ parent_league_id <int> 130, NA, NA, NA, NA, NA, NA, 9134, 9296, 48, 230, 1…
#> $ internal_rank <int> 10, 30, 10, 9, 20, 10, 9, 2, 8, 29, 10, 0, 0, 7, 7,…
#> $ live_rank <int> 100, 101, 100, 100, 100, 100, 0, 0, 0, 0, 0, 0, 0, …
#> $ simple_league <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
#> $ is_group <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
#> $ group_name <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
#> $ parent_league_name <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
filtered_results <- results %>%
dplyr::select(primary_id, ccode, league_name = name, matches) %>%
dplyr::filter(league_name == "Premier League", ccode == "ENG")
# one way of getting data out of the results
unnested_results <- filtered_results %>%
tidyr::unnest_longer(matches)
match_ids <- unnested_results %>%
dplyr::pull(matches) %>%
dplyr::pull(id)
match_ids
#> [1] 3609981 3609986 3609983 3609984 3609985 3609988 3609980 3609987 3609979
Note that fotmob returns nested data.frames or lists for some elements. Nested components have camel case names.
unnested_results %>%
dplyr::pull(matches) %>%
dplyr::glimpse()
#> Rows: 9
#> Columns: 11
#> $ id <int> 3609981, 3609986, 3609983, 3609984, 3609985, 3609988,…
#> $ leagueId <int> 47, 47, 47, 47, 47, 47, 47, 47, 47
#> $ time <chr> "25.09.2021 13:30", "25.09.2021 13:30", "25.09.2021 1…
#> $ home <df[,4]> <data.frame[9 x 4]>
#> $ away <df[,4]> <data.frame[9 x 4]>
#> $ eliminatedTeamId <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA
#> $ statusId <int> 6, 6, 6, 6, 6, 6, 6, 6, 6
#> $ tournamentStage <chr> "6", "6", "6", "6", "6", "6", "6", "6", "6"
#> $ status <df[,7]> <data.frame[9 x 7]>
#> $ timeTS <dbl> 1.632551e+12, 1.632551e+12, 1.632560e+12, 1.632560e+1…
#> $ tv <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA
You should see international tournaments in the output from fotmob_get_matches_by_date()
.
results <- fotmob_get_matches_by_date("20220412")
results %>%
dplyr::select(primary_id, ccode, league_name = name, matches) %>%
dplyr::filter(league_name == "Champions League Final Stage", ccode == "INT")
#> # A tibble: 1 × 4
#> primary_id ccode league_name matches
#> <int> <chr> <chr> <list>
#> 1 42 INT Champions League Final Stage <df [2 × 11]>
Standings for one or multiple leagues can be retrieved with fotmob_get_league_tables
. Currently only the current season’s standings can be retrieved.
league_tables <- fotmob_get_league_tables(
country = c("ENG", "ESP" ),
league_name = c("Premier League", "LaLiga")
)
# or
# league_tables <- fotmob_get_league_tables(league_id = c(47, 87))
away_league_tables <- league_tables %>%
dplyr::filter(table_type == "away")
dplyr::glimpse(away_league_tables)
#> Rows: 40
#> Columns: 16
#> $ league_id <int> 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, …
#> $ page_url <chr> "/leagues/47/overview/premier-league", "/leagues/47/over…
#> $ table_type <chr> "away", "away", "away", "away", "away", "away", "away", …
#> $ name <chr> "Man City", "Liverpool", "Chelsea", "Tottenham", "Bright…
#> $ id <int> 8456, 8650, 8455, 8586, 10204, 9825, 8602, 8654, 10260, …
#> $ team_page_url <chr> "/teams/8456/overview/manchester-city", "/teams/8650/ove…
#> $ deduction <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ played <int> 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, …
#> $ wins <int> 14, 13, 12, 9, 7, 9, 8, 7, 6, 7, 6, 5, 4, 5, 4, 4, 3, 2,…
#> $ draws <int> 4, 4, 4, 4, 8, 1, 3, 3, 5, 1, 4, 5, 7, 4, 6, 3, 6, 8, 4,…
#> $ losses <int> 1, 2, 3, 6, 4, 9, 8, 9, 8, 11, 9, 9, 8, 10, 9, 12, 10, 9…
#> $ scores_str <chr> "41-11", "45-17", "39-11", "31-21", "23-21", "26-31", "1…
#> $ goal_con_diff <int> 30, 28, 28, 10, 2, -5, 0, 2, -10, -2, -9, -18, -6, -17, …
#> $ pts <int> 46, 43, 40, 31, 29, 28, 27, 24, 23, 22, 22, 20, 19, 19, …
#> $ idx <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1…
#> $ qual_color <chr> "#2AD572", "#2AD572", "#2AD572", "#2AD572", "#0046A7", "…
Note that the output of fotmob_get_league_tables
for a tournament has more columns.
cl_table <- fotmob_get_league_tables(league_id = 42)
cl_table %>%
dplyr::filter(table_type == "all") %>%
dplyr::glimpse()
#> Rows: 32
#> Columns: 20
#> $ league_id <int> 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,…
#> $ page_url <chr> "/leagues/42/overview/champions-league", "/leagues/42/o…
#> $ ccode <chr> "", "", "", "", "", "", "", "", "", "", "", "", "", "",…
#> $ group_id <int> 875009, 875009, 875009, 875009, 875010, 875010, 875010,…
#> $ group_page_url <chr> "/leagues/875009/overview/grp.-a", "/leagues/875009/ove…
#> $ group_name <chr> "Grp. A", "Grp. A", "Grp. A", "Grp. A", "Grp. B", "Grp.…
#> $ table_type <chr> "all", "all", "all", "all", "all", "all", "all", "all",…
#> $ name <chr> "Man City", "PSG", "RB Leipzig", "Club Brugge", "Liverp…
#> $ id <int> 8456, 9847, 178475, 8342, 8650, 9906, 9773, 8564, 8593,…
#> $ team_page_url <chr> "/teams/8456/overview/manchester-city", "/teams/9847/ov…
#> $ deduction <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
#> $ played <int> 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6…
#> $ wins <int> 4, 3, 2, 1, 6, 2, 1, 1, 6, 3, 3, 0, 5, 3, 2, 0, 6, 2, 2…
#> $ draws <int> 0, 2, 1, 1, 0, 1, 2, 1, 0, 0, 0, 0, 0, 1, 1, 2, 0, 2, 1…
#> $ losses <int> 2, 1, 3, 4, 0, 3, 3, 4, 0, 3, 3, 6, 1, 2, 3, 4, 0, 2, 3…
#> $ scores_str <chr> "18-10", "13-8", "15-14", "6-20", "17-6", "7-8", "4-11"…
#> $ goal_con_diff <int> 8, 5, 1, -14, 11, -1, -7, -3, 15, 2, -1, -16, 11, 3, -4…
#> $ pts <int> 12, 11, 7, 4, 18, 7, 5, 4, 18, 9, 9, 0, 15, 10, 7, 2, 1…
#> $ idx <int> 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3…
#> $ qual_color <chr> "#2AD572", "#2AD572", "#FFD908", NA, "#2AD572", "#2AD57…
To get shooting locations for an individual match along with expected goals (xG), expected goals on target (xGoT), etc., use the fotmob_get_match_details()
function.
fotmob_matches <- c(3609994, 3610132)
match_details <- fotmob_get_match_details(fotmob_matches)
dplyr::glimpse(match_details)
#> Rows: 2
#> Columns: 15
#> $ match_id <int> 3609994, 3610132
#> $ match_round <chr> "7", "21"
#> $ league_id <int> 47, 47
#> $ league_name <chr> "Premier League", "Premier League"
#> $ league_round_name <chr> "Premier League Round 7", "Premier League Round 2…
#> $ parent_league_id <int> 47, 47
#> $ parent_league_season <chr> "2021/2022", "2021/2022"
#> $ match_time_utc <chr> "Sun, Oct 3, 2021, 15:30 UTC", "Sun, Jan 2, 2022,…
#> $ home_team_id <int> 8650, 8455
#> $ home_team <chr> "Liverpool", "Chelsea"
#> $ home_team_color <chr> "#d3171e", "#064b95"
#> $ away_team_id <int> 8456, 8650
#> $ away_team <chr> "Manchester City", "Liverpool"
#> $ away_team_color <chr> "#69A8D8", "#d3171e"
#> $ shots <list> [<data.frame[18 x 24]>], [<data.frame[25 x 24]>]
match_shots <- match_details %>%
dplyr::select(
match_id,
shots
) %>%
tidyr::unnest(shots)
dplyr::glimpse(match_shots)
#> Rows: 43
#> Columns: 25
#> $ match_id <int> 3609994, 3609994, 3609994, 3609994, 3609994, …
#> $ id <dbl> 2338869639, 2338876703, 2338881401, 233888382…
#> $ event_type <chr> "AttemptSaved", "AttemptSaved", "AttemptSaved…
#> $ team_id <int> 8650, 8456, 8456, 8456, 8456, 8456, 8456, 845…
#> $ player_id <int> 292462, 312765, 815006, 169200, 169200, 16920…
#> $ player_name <chr> "Mohamed Salah", "Jack Grealish", "Phil Foden…
#> $ x <dbl> 92.50000, 91.50000, 100.35345, 97.57017, 97.0…
#> $ y <dbl> 50.72688, 49.53580, 42.00375, 46.31286, 28.95…
#> $ min <int> 8, 15, 21, 24, 34, 38, 40, 40, 50, 59, 63, 67…
#> $ min_added <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
#> $ is_blocked <lgl> TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, …
#> $ is_on_target <lgl> TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, F…
#> $ blocked_x <dbl> 94.48246, 93.40000, 101.87069, 104.05172, NA,…
#> $ blocked_y <dbl> 48.20459, 47.57401, 39.54500, 0.00000, NA, 28…
#> $ goal_crossed_y <dbl> 34.6100000, 34.8387500, 32.7800000, 0.3279621…
#> $ goal_crossed_z <dbl> 1.21999999, 1.21999999, 0.36600000, 0.5329473…
#> $ expected_goals <dbl> 0.04540855, 0.04835442, 0.63251555, 0.0870914…
#> $ expected_goals_on_target <dbl> NA, NA, 0.6931, NA, NA, NA, NA, NA, 0.0412, 0…
#> $ shot_type <chr> "LeftFoot", "RightFoot", "LeftFoot", "LeftFoo…
#> $ situation <chr> "FromCorner", "RegularPlay", "RegularPlay", "…
#> $ period <chr> "FirstHalf", "FirstHalf", "FirstHalf", "First…
#> $ is_own_goal <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FAL…
#> $ on_goal_shot <df[,3]> <data.frame[26 x 3]>
#> $ first_name <chr> "Mohamed", "Jack", "Phil", "Kevin", "Kevin…
#> $ last_name <chr> "Salah", "Grealish", "Foden", "De Bruyne", "D…
There is one nested element in the returned data.frame for on_goal_shot
. As with the nested elements returned by fotmob_get_matches_by_date
, columns in nested elements have camel case names. (Here, it’s only zoomRatio
.)
NOTE: The below code block depends on tidyr 1.2.0
match_shots %>%
dplyr::select(on_goal_shot) %>%
tidyr::unnest_wider(
on_goal_shot
)
#> # A tibble: 43 × 3
#> x y zoomRatio
#> <dbl> <dbl> <dbl>
#> 1 0.839 0.323 1
#> 2 0.778 0.323 1
#> 3 1.32 0.0968 1
#> 4 2 0.0158 0.112
#> 5 1.38 0.677 0.461
#> 6 1.14 0.323 1
#> 7 1.14 0.323 1
#> 8 0 0.0255 0.181
#> 9 1.26 0.216 1
#> 10 0.476 0.0221 1
#> # … with 33 more rows
Be very careful with interpreting x
and y
from on_goal_shot
. They’re not on the same scale as x
and y
in the top-level of the result returned from fotmob_get_match_details
!
You can also extract players from matches with the fotmob_get_match_players()
function.
players <- fotmob_get_match_players(fotmob_matches)
dplyr::glimpse(players)
#> Rows: 80
#> Columns: 32
#> $ match_id <int> 3609994, 3609994, 3609994, 3609994, 3609994, 360…
#> $ team_id <int> 8650, 8650, 8650, 8650, 8650, 8650, 8650, 8650, …
#> $ team_name <chr> "Liverpool", "Liverpool", "Liverpool", "Liverpoo…
#> $ id <chr> "319784", "38807", "171698", "209405", "357880",…
#> $ using_opta_id <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
#> $ first_name <chr> "Alisson", "James", "Joel", "Virgil", "Andrew", …
#> $ last_name <chr> "Becker", "Milner", "Matip", "van Dijk", "Robert…
#> $ image_url <chr> "https://images.fotmob.com/image_resources/playe…
#> $ page_url <chr> "/players/319784/alisson-becker", "/players/3880…
#> $ shirt <chr> "1", "7", "32", "4", "26", "14", "3", "17", "11"…
#> $ is_home_team <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, …
#> $ time_subbed_on <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ time_subbed_off <int> NA, 78, NA, NA, NA, NA, NA, NA, NA, 68, NA, NA, …
#> $ usual_position <int> 0, 2, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 2, 2, …
#> $ position_row <int> 0, 1, 1, 1, 1, 3, 3, 3, 5, 5, 5, 5, 5, 5, 3, 3, …
#> $ role <chr> "Keeper", "Midfielder", "Defender", "Defender", …
#> $ is_captain <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, …
#> $ subbed_out <int> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …
#> $ g <int> NA, NA, NA, NA, NA, NA, NA, NA, 1, NA, 1, 1, NA,…
#> $ rating_num <chr> "5.7", "7.2", "7.3", "6.6", "7.2", "7.2", "6.3",…
#> $ rating_bgcolor <chr> "#f08022", "#1ec853", "#1ec853", "#f08022", "#1e…
#> $ is_top_rating <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,…
#> $ is_match_finished <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, …
#> $ fantasy_score_num <chr> "1", "1", "1", "1", "1", "2", "1", "5 + 2", "10 …
#> $ fantasy_score_bgcolor <chr> "purple", "purple", "purple", "purple", "purple"…
#> $ home_team_id <int> 8650, 8650, 8650, 8650, 8650, 8650, 8650, 8650, …
#> $ home_team_color <chr> "#d3171e", "#d3171e", "#d3171e", "#d3171e", "#d3…
#> $ away_team_id <int> 8456, 8456, 8456, 8456, 8456, 8456, 8456, 8456, …
#> $ away_team_color <chr> "#69A8D8", "#69A8D8", "#69A8D8", "#69A8D8", "#69…
#> $ stats <df[,41]> <data.frame[26 x 41]>
#> $ shotmap <list> <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NUL…
#> $ is_starter <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,…
salah <- players %>% dplyr::filter(id == "292462")
salah_shotmap <- salah %>%
dplyr::select(player_id = id, shotmap) %>%
tidyr::unnest(shotmap)
dplyr::glimpse(salah_shotmap)
#> Rows: 7
#> Columns: 23
#> $ player_id <chr> "292462", "292462", "292462", "292462", "292462"…
#> $ id <dbl> 2338869639, 2338938757, 2338947917, 2371191153, …
#> $ eventType <chr> "AttemptSaved", "AttemptSaved", "Goal", "Attempt…
#> $ teamId <int> 8650, 8650, 8650, 8650, 8650, 8650, 8650
#> $ playerId <int> 292462, 292462, 292462, 292462, 292462, 292462, …
#> $ playerName <chr> "Mohamed Salah", "Mohamed Salah", "Mohamed Salah…
#> $ x <dbl> 92.50000, 80.57039, 101.87069, 90.00000, 101.396…
#> $ y <dbl> 50.72688, 45.26191, 24.27949, 33.31375, 24.13936…
#> $ min <int> 8, 63, 76, 6, 26, 36, 57
#> $ minAdded <lgl> NA, NA, NA, NA, NA, NA, NA
#> $ isBlocked <lgl> TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE
#> $ isOnTarget <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE
#> $ blockedX <dbl> 94.48246, 90.80000, NA, 97.76316, NA, 93.10000, …
#> $ blockedY <dbl> 48.20459, 40.97381, NA, 33.69500, NA, 30.22000, …
#> $ goalCrossedY <dbl> 34.61000, 33.39000, 37.27875, 34.68625, 32.01750…
#> $ goalCrossedZ <dbl> 1.220000, 1.220000, 1.136526, 0.854000, 1.014526…
#> $ expectedGoals <dbl> 0.04540855, 0.04966947, 0.29863000, 0.17881796, …
#> $ expectedGoalsOnTarget <dbl> NA, NA, 0.9744, 0.1107, 0.2217, NA, 0.2100
#> $ shotType <chr> "LeftFoot", "LeftFoot", "RightFoot", "RightFoot"…
#> $ situation <chr> "FromCorner", "FreeKick", "RegularPlay", "Regula…
#> $ period <chr> "FirstHalf", "SecondHalf", "SecondHalf", "FirstH…
#> $ isOwnGoal <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE
#> $ onGoalShot <df[,3]> <data.frame[7 x 3]>
salah_stats <- salah %>%
dplyr::select(stats) %>%
tidyr::unnest(stats)
dplyr::glimpse(salah_stats)
#> Rows: 2
#> Columns: 41
#> $ stats_fot_mob_rating <dbl> 8.85, 7.99
#> $ stats_minutes_played <dbl> 90, 90
#> $ stats_saves <dbl> NA, NA
#> $ stats_goals <dbl> 1, 1
#> $ stats_goals_conceded <dbl> NA, NA
#> $ stats_x_got_faced <dbl> NA, NA
#> $ stats_diving_save <dbl> NA, NA
#> $ stats_saves_inside_box <dbl> NA, NA
#> $ stats_acted_as_sweeper <dbl> NA, NA
#> $ stats_punches <dbl> NA, NA
#> $ stats_throws <dbl> NA, NA
#> $ stats_high_claim <dbl> NA, NA
#> $ stats_recoveries <dbl> 1, 2
#> $ stats_fantasy_points <dbl> NA, 7
#> $ stats_touches <dbl> 49, 41
#> $ stats_assists <dbl> 1, 0
#> $ stats_total_shots <dbl> 3, 4
#> $ stats_chances_created <dbl> 2, 2
#> $ stats_expected_assists_x_a <dbl> 0.29, 0.04
#> $ stats_corners <dbl> NA, NA
#> $ stats_dispossessed <dbl> 1, 1
#> $ stats_tackles_won <dbl> NA, 0
#> $ stats_blocks <dbl> NA, NA
#> $ stats_clearances <dbl> 1, NA
#> $ stats_interceptions <dbl> 1, 1
#> $ stats_was_fouled <dbl> 1, 0
#> $ stats_fouls_committed <dbl> 0, 1
#> $ stats_headed_clearance <dbl> 1, NA
#> $ stats_aerial_duels_won <dbl> NA, 0
#> $ stats_dribbled_past <dbl> 1, NA
#> $ stats_offsides <dbl> NA, 1
#> $ stats_expected_goals_x_g <dbl> 0.39, 0.71
#> $ stats_big_chance_missed <dbl> NA, 1
#> $ stats_expected_goals_on_target_x_got <dbl> 0.97, 0.54
#> $ stats_blocked_shots <dbl> 2, 1
#> $ stats_clearance_off_the_line <dbl> NA, NA
#> $ stats_ground_duels_won <dbl> NA, NA
#> $ stats_accurate_passes <dbl> NA, NA
#> $ stats_accurate_long_balls <dbl> NA, NA
#> $ stats_error_led_to_goal <dbl> NA, NA
#> $ stats_last_man_tackle <dbl> NA, NA