Not to sound too nostalgic, but when i first started messing about with football event data I was manually plotting Oxford shot locations and visualising in Tableau. Access to to data was limited, however we currently have more access to data than has ever previously been available.
A few resources:
- Statsbomb (covered in previous posts)
- Canadian Premier League (yet to dive in but a super interesting league and regularly updated data)
- Wyscout (top 5 european leagues 2017-2018)
- UnderstatR (will use this in this post)
This tweet from Sushruta Nandy prompted me to write this.
Anyway, the plan:
- Load up Tidverse and UnderstatR
- Run 2019 team/player data
- Extract 2019 x/y shot locations
- Save to .csv
Here we go then....
1) Load in Tidverse and UnderstatR
2) Set the working directory (will need this later when saving the data to .csv - just select the path you wish for the file to be saved to)
At this point, you should have something pretty straight forward:
Right, lets dig into the UnderstatR package:
We can use the get_leagues_meta() to observe the available leagues. Run this and you will see leagues are available from 2014-2019 (plus the start of a few 2020 seasons at the time of writing!). This includes the EFL, La Liga, Bundesliga, Ligue 1, Serie A and RFPL.
As we are focussed on the top 5 European leagues we can drop the RFPL using the dplyr filter. At this point we should have:
Check 'leagues' and you should have:
Great - now to pull team data:
team_data<-map_dfr(unique(leagues$league_name), get_league_teams_stats, year = 2019)
This will use the purrr package to cycle through each unique league name and pull the team data for each match within the top 5 leagues in 2019. We end up with a data frame of 3450 rows including individual match xG, xGA, NPxG etc.
Call team_data to have a little look - this is useful in itself but we can take this a step further to obtain player data:
player_data<-map_dfr(unique(team_data$team_name), get_team_players_stats, year = 2019)
Once more this runs through each team getting the 2019 players stats. This may take a minute, however once done this will create a database of 2732 players and their summary stats for 2019:
Another example:
This comment has been removed by the author.
ReplyDeleteCould you please share the code for plotting "Douglas Costa shot assist locations in 2019"?
ReplyDeleteCL 4K UHD Video Player - all video format player – App
ReplyDeleteCL 4K UHD Player- High Quality Video Player app allows you to watch your favorite movies, shows and other videos in Ultra HD quality. You can watch high quality videos from your device or SD card and stream from web. This app also works as whatsapp status downloader.
Install CL 4K UHD Player- High Quality Video Player on your android device and enjoy 4K ultra HD videos anytime, anywhere. all video format player