Closed Ryo-N7 closed 5 years ago
Hi Ryo,
The issue here is needing to process the raw data retrieved by get.matchFree()
using other StatsBombR
functions like cleanlocations()
. I made a helper function in a fork of the package here to automate this process if you're interested.
Once you have the cleaned data containing variables location.x
and location.y
, you need to use the soccerTransform()
function with option method = "statsbomb"
to convert the data from StatsBomb coordinates (1 <= x <= 120, 1 <= y <= 80) to metre units for plotting with soccermatics
(by default this function uses 105m x 68m for pitch length and width, as do other soccermatics
functions, but you can specify alternative pitch dimensions).
Code should look something like this then:
library(dplyr)
# get Japan matches
WC_Matches <- StatsBombR::FreeMatches(43)
JPN_Matches <- WC_Matches %>%
filter(home_team.home_team_id == 778 | away_team.away_team_id == 778)
# get all StatsBomb data
jp <- StatsBombR::allinfo(JPN_Matches)
# transform x,y-coords to real-world units for compatability with soccermatics
jp <- jp %>%
soccermatics::soccerTransform(method = "statsbomb")
# shotmap for multiple matches
jp %>%
filter(player.name == "Takashi Inui") %>%
soccermatics::soccerShotmap(theme = "grey",
title = "Takashi Inui",
subtitle = "World Cup 2018")
# passmap for one match
jp_sen <- jp %>%
filter(match_id == 7556)
jp_sen %>%
filter(team.name == "Japan") %>%
soccermatics::soccerPassmap(fill = "lightblue", arrow = "r", theme = "light",
title = "Japan (vs. Senegal, World Cup 2018)")
Hope that helps!
ah I was looking at the soccerTransform()
function but didn't think to look at anything in StatsBombR...
Thank you very much!
hey Joe!
been trying to use your recently updated package. I've been trying to replicate the cool graphs you showed with the sample data (Griezmann and France shot/pass maps) with other world cup matches but I keep running into a problem regarding the location data necessary to pass onto the graph functions like
soccerShotmap()
,soccerPassmap()
, etc.The matches I tried were Japan vs. Senegal, Japan vs. Belgium, and Brazil vs. Costa Rica.
For example:
then I would get the error:
Error in FUN(X[[i]], ...) : object 'location.y' not found
I tried to separate the coordinates found in the "location" column like so:
but I get a empty map with the text data but no points on the field.
Here's another example with the
soccerPassmap()
function:Is there anyway you could tell me where/what that "location.x" and "location.y" data columns are supposed to be? Just checking the example data set, the coordinates in "location.x" and "location.y" seem to be very different from the coordinates in "location" so maybe I'm missing something in processing it?
Sorry for the long post, any help would be appreciated!