abhiamishra / ggshakeR

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

[Bug]: Pass plots not working with non statsbomb/opta data #111

Closed MaundoJako closed 1 year ago

MaundoJako commented 1 year ago

What happened?

I am using code scraped from WhoScored. I have the necessary data, however, the plots return false results. This is the case for all the plot functions with ggshakeR.

Data: stoke vs boro.xlsx

Screenshot examples:

Screenshot 2022-08-19 at 13 31 05

image

ggshakeR version: 0.2.0.9000 R version: RStudio 2022.07.1+554 "Spotted Wakerobin" Release (7872775ebddc40635780ca1ed238934c3345c5de, 2022-07-22) for macOS Mozilla/5.0 (Macintosh; Intel Mac OS X 12_0_1) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.10 Chrome/69.0.3497.128 Safari/537.36

Never done a reprex before, hope this works for you?

``` r
library(readxl)
data1 <- read_excel("Documents/stoke vs boro.xlsx")
#> Error: `path` does not exist: 'Documents/stoke vs boro.xlsx'
View(data1)
#> Error in as.data.frame(x): object 'data1' not found
library(reprex)

plotting_data <- data1 %>%
  rename("finalX" = "endX",
         "finalY" = "endY",
         "type.name" = "type/displayName",
         "player.name" = "playerId",
         "pass.outcome.name" = "outcomeType/displayName",
         "team.name" = "teamId")
#> Error in data1 %>% rename(finalX = "endX", finalY = "endY", type.name = "type/displayName", : could not find function "%>%"
view(plotting_data)
#> Error in view(plotting_data): could not find function "view"

plotting_data_gayle <- plotting_data %>%
  filter(type.name == "Pass" & team.name == "Stoke City" & player.name == "Dwight Gayle")
#> Error in plotting_data %>% filter(type.name == "Pass" & team.name == "Stoke City" & : could not find function "%>%"
passPlot <- plot_pass(data = plotting_data_gayle, progressive_pass = FALSE, type = "all")
#> Error in plot_pass(data = plotting_data_gayle, progressive_pass = FALSE, : could not find function "plot_pass"
passPlot
#> Error in eval(expr, envir, enclos): object 'passPlot' not found

passflowPlot <- plot_passflow(data = plotting_data_gayle)
#> Error in plot_passflow(data = plotting_data_gayle): could not find function "plot_passflow"
passflowPlot
#> Error in eval(expr, envir, enclos): object 'passflowPlot' not found

convexPlot <- plotting_data %>%
  filter(match_id == 1, team.name == "Stoke City") %>%
  plot_convexhull()
#> Error in plotting_data %>% filter(match_id == 1, team.name == "Stoke City") %>% : could not find function "%>%"
convexPlot
#> Error in eval(expr, envir, enclos): object 'convexPlot' not found

passnetPlot <- plotting_data %>%
  filter(match_id == 1) %>%
  plot_passnet(team_name = "Stoke City")
#> Error in plotting_data %>% filter(match_id == 1) %>% plot_passnet(team_name = "Stoke City"): could not find function "%>%"
passnetPlot
#> Error in eval(expr, envir, enclos): object 'passnetPlot' not found

Created on 2022-08-19 with reprex v2.0.2

harshkrishna17 commented 1 year ago

Hey! So the main thing is that the default data_type in all our event data functions is set to statsbomb. Since your data is from opta, you would need to set it as such. Adding in a data_type = "opta" within the function should do the trick.

MaundoJako commented 1 year ago

Hey, I thought this originally. Though, still doesn't work i'm afraid. This is the outcome: image

CODE: plotting_data_gayle <- plotting_data %>% filter(type.name == "Pass" & team.name == "Stoke City" & player.name == "Dwight Gayle") passPlot <- plot_pass(data_type = "opta", data = plotting_data_gayle, progressive_pass = FALSE, type = "all") passPlot

harshkrishna17 commented 1 year ago

The plot_passnet error can be resolved by running the following code.

data <- readxl::read_xlsx("stoke.vs.boro.xlsx")

data <- data %>%
  rename("finalX" = "endX",
         "finalY" = "endY",
         "type" = "type/displayName",
         "outcome" = "outcomeType/displayName")

data %>%
  filter(match_id == 1) %>%
  plot_passnet(team_name = "Stoke City", data_type = "opta")  

image

harshkrishna17 commented 1 year ago

Will get back to you shortly for the plot_pass error

harshkrishna17 commented 1 year ago

Found the error in the plot_pass source code. A fix will be pushed shortly

abhiamishra commented 1 year ago

What was the issue in the plot_pass code @harshkrishna17

abhiamishra commented 1 year ago

Is it flipped / reversed?

abhiamishra commented 1 year ago

@MaundoJako I am working on the fix for plot_pass(). Can you confirm for us that the others, passflow, convex, and voronoi, are working correctly when you set it to Opta?

abhiamishra commented 1 year ago

Seem to have found the error - so in our pitch plots, we convert all data types to one final data type when showing the plot - that type is StatsBomb.

Looks like there is an error w converting Opta to Statsbomb

MaundoJako commented 1 year ago

@MaundoJako I am working on the fix for plot_pass(). Can you confirm for us that the others, passflow, convex, and voronoi, are working correctly when you set it to Opta?

Hey, Convex works fine. plot_passflow() doesnt work, and I dont think pass_sonar() is working either. Have not tried voronoi yet.

abhiamishra commented 1 year ago

@MaundoJako I am working on the fix for plot_pass(). Can you confirm for us that the others, passflow, convex, and voronoi, are working correctly when you set it to Opta?

Hey, Convex works fine. plot_passflow() doesnt work, and I dont think pass_sonar() is working either. Have not tried voronoi yet.

Can you show us the results for passflow and pass_sonar? They should work as they pretty straightword functions

abhiamishra commented 1 year ago

Opta dataset with plot_pass function Opta dataset with plot_pass function

OP's code OP's code

Seems like the issue is fixed - if I can get what's wrong with the others, the fix should be similar but I want to double check

MaundoJako commented 1 year ago

Im not sure if the pass_sonar is incorrect, just my eye test thinks it might be. Looking at the picture below, I feel like should be more forward passes shown in the sonar.

Picture 1

abhiamishra commented 1 year ago

Im not sure if the pass_sonar is incorrect, just my eye test thinks it might be. Looking at the picture below, I feel like should be more forward passes shown in the sonar.

Picture 1

Hmm, I actually think it summarize it well. It's not directly forward well but if you look, there is an arrow that is very long that is slightly angled to the left and forward - I feel like the congestion of the passes doesn't allow us to see the direction of the pass therefore why it seem off?

Try it on several players - that's how I tested plot_sonar

MaundoJako commented 1 year ago

For pass_flow, similar explanation as before. I think it might just be flipped? I can solve this issue by scale_y_reverse, look below.

image image
abhiamishra commented 1 year ago

For pass_flow, similar explanation as before. I think it might just be flipped? I can solve this issue by scale_y_reverse, look below.

image image

yeah ill double check this but that seems to be it too

you said you had problems with voronoi as well - is it the same issue? flipped

MaundoJako commented 1 year ago

Havent tried voronoi yet. Ill let you know if I have any problems.

For the heatmap(), I dont get any result, just a blank football pitch. Im not sure if this is because Im only plotting from 1 game. In your tutorial you use a season's worth.

harshkrishna17 commented 1 year ago

what is the code you use for plot_heatmap() ?

abhiamishra commented 1 year ago

Havent tried voronoi yet. Ill let you know if I have any problems.

For the heatmap(), I dont get any result, just a blank football pitch. Im not sure if this is because Im only plotting from 1 game. In your tutorial you use a season's worth.

I am able to get heatmap all fine image

abhiamishra commented 1 year ago

Havent tried voronoi yet. Ill let you know if I have any problems. For the heatmap(), I dont get any result, just a blank football pitch. Im not sure if this is because Im only plotting from 1 game. In your tutorial you use a season's worth.

I am able to get heatmap all fine image

that too with jdp, density, hex, etc: image

abhiamishra commented 1 year ago

Plot_passmap definitely needed the scale_y_reverse: image

image

abhiamishra commented 1 year ago

Functions fixed:

Functions in progress of being fixed:

MaundoJako commented 1 year ago

what is the code you use for plot_heatmap() ?

Apologies, plot_heatmap() is working fine now. I had type = "bin" from the online tutorial: https://abhiamishra.github.io/ggshakeR/articles/Guide_to_Pitch_Plots.html

Works fine with the correct types.

Cheers for your help lads! :)

MaundoJako commented 1 year ago

FYI, voronoi works fine with me