abhiamishra / ggshakeR

An analysis and visualization R package that works with publicly available soccer data
https://abhiamishra.github.io/ggshakeR/
MIT License
113 stars 14 forks source link

[Bug]: Possible error in plot_passnet flip logic? #108

Closed zpy86 closed 2 years ago

zpy86 commented 2 years ago

What happened?

Hi, I tried to create some Germany passmaps from this summer's EURO using the free StatBomb data and noticed oddities. Players seemed to display on the wrong sides of the field. I tried toggling the flip parameter to plot_passnet, and it produces different results -- see: https://imgur.com/a/2TXHL7x -- but neither looks 'correct'. Including one image for example:

example passnet

For context, the 4-3-3 personnel on the field were:

With flip = TRUE:

With flip = FALSE (as in the included image above):

I'm not 100% positive this isn't an issue in the data itself either. For example, it's odd that Hegering (RCB) always has a strong line to Rauch (LB) in either orientation, but no line to Gwinn (RB).

However, thought I would report here, (1) in case I have some kind of error in my example and (2) because regardless of data I don't believe toggling the flip option should result in wingers, fullbacks swapping sides in the graphic like this.

Odd because for example I see other uses of this function online where the results look correct, but I can't figure out what I might be doing wrong on my part.

If I had to guess, the underlying data is correct but there's something going wrong when it comes to deciding which name to put where, in either orientation. And perhaps the above Twitter example where it looks correct comes from an older version of ggshakeR.


ggshakeR version: ggshakeR_0.2.0.9000 also StatsBombR_0.1.0 R version: 4.2.1 (2022-06-23 svn rev 82513)

require(StatsBombR)
require(ggshakeR)

COMP_ID = 53 # UEFA Women's EURO 2022
TEAM_ID = 857 # Germany
TEAM_NAME = "Germany Women's"

Comp <- FreeCompetitions() %>%
  filter(competition_id == 53)

# Could also include their away games
Matches <- FreeMatches(Comp) %>%
  filter(home_team.home_team_id == TEAM_ID)
StatsBombData <- free_allevents(MatchesDF = Matches, Parallel = TRUE)
plotting_data  <- allclean(StatsBombData)

plotting_data <- plotting_data %>%
  rename("x" = "location.x",
         "y" = "location.y",
         "finalX" = "pass.end_location.x",
         "finalY" = "pass.end_location.y")

match_ids <- Matches$match_id

unique(plotting_data$match_id) # Find all match IDs from data set

# Take one of their matches for example
passnetPlot <- plotting_data %>%
  filter(match_id == match_ids[2]) %>%
  plot_passnet(team_name = TEAM_NAME)

passnetPlot
harshkrishna17 commented 2 years ago

Hey! Firstly thanks for putting up a perfectly documented issue. Also yes, there is a problem with the function. I seem to have overlooked the direction and orientation of the function when working with StatsBomb data. I'll get to fixing it. It'll be done by today.

harshkrishna17 commented 2 years ago

Does this look correct? @zpy86

plot

zpy86 commented 2 years ago

Thanks!! Yes, that looks good! Also, my bad -- I switched the CBs myself, but upon checking the highlights for that game it does indeed look like Hegering was the LCB and Hendrich on the right.

harshkrishna17 commented 2 years ago

Removing the flip parameter for now. Too many moving parts so cannot seem to get it to work with StatsBomb data. Will bring it back later once I figure out how to fix it.

harshkrishna17 commented 2 years ago

@zpy86 issue closed as completed. You can install the latest version for the fix