JoGall / soccermatics

Tools for visualisation and analysis of soccer tracking and event data
308 stars 36 forks source link

soccerShotmap plotted as mirror image #15

Closed TimHoare closed 5 years ago

TimHoare commented 5 years ago

When I plot an xG map using soccerShotmap, the locations are appearing as a mirror image as where they should be. I used soccerTransform to adjust the coordinates an all Statsbomb data which fixed a similar issue for soccerPassmap however this seems to have created a new issue for the shot map. Should I be using the normal Statsbomb coordinates in this case (i.e. should I not have used soccerTransform here) or is it an unrelated issue do you think?

Thanks

JoGall commented 5 years ago

StatsBomb reports their x,y-coordinates for both teams as if attacking from left to right, so the shots won't always be the orientation they appeared from the camera angle (i.e. they will appear mirror imaged when a team was attacking from right to left).

If you want to mirror the locations for plotting you could just subtract the y-coordinates from the y maximum (120 if raw StatsBomb coordinates, whatever your widthPitch is if coordinates are transformed). e.g.:

# raw data from StatsBombR (1 < x < 120, 1 < y < 80)
fawsl_dat <- d %>% 
  filter(match_id == 19746)

# mirror y-coords
dat <- dat %>% 
  mutate(location.y = 80 - location.y)

# transform from StatsBomb x,y-coords to metre units
dat <- dat %>% 
  soccerTransform(method = "statsbomb")

# plot shotmap
dat %>% 
  filter(team.id == 967) %>% 
  soccerShotmap()