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]: #121

Closed Zakgas closed 1 year ago

Zakgas commented 1 year ago

What happened?

Hi,

When trying to run your code on the ggShakeR website for Tammy Abraham:

library(worldfootballR)

single_player <- fb_player_scouting_report("https://fbref.com/en/players/f586779e/Tammy-Abraham", pos_versus = "primary")

pizza <- plot_pizza(data = single_player, type = "single", template = "outfielder", 
                    color_possession = "#41ab5d", color_attack = "#fec44f", color_defense = "#de2d26", 
                    season = "Last 365 Days", theme = "dark")

pizza

I get the following error:

Error in plot_pizza(data = single_player, type = "single", template = "outfielder",  : 
  object 'data_selected' not found

Any help would be much appreciated.

Best, Zakariah

abhiamishra commented 1 year ago

hi @Zakgas - sorry for the late response.

it seems that there is a problem not with ggshakeR but rather the scraping.

can you confirm if the dataframe single_player has a size and has data?

Zakgas commented 1 year ago

Hi @abhiamishra,

I can confirm that the dataframe single_player has a size and has data

abhiamishra commented 1 year ago

hey @Zakgas - sorry for the late response again; i will try to run and see what the issue is

JaseZiv commented 1 year ago

Hey @abhiamishra,

I know the reason for this bug...

I pushed an update to worldfootballR to fix a bug that was introduced when FBRef switched providers from StatsBomb to Opta. This led to them changing the format of the scouting data, more variables, time periods to com[are, etc. See this GH issue in worldfootballR: https://github.com/JaseZiv/worldfootballR/issues/242

and the PR that resolved it: https://github.com/JaseZiv/worldfootballR/pull/245.

I believe the issue in ggshakeR::plot_pizza() stems from the manual indexing of rows here:

https://github.com/abhiamishra/ggshakeR/blob/main/R/plot_pizza.R#L108-L112

image

This would also need to be replicated in the if statement based on whether type == "comparison"...

I would raise a PR to fix myself, just need to know what columns you wanted returned. Let me know if you want me to help.

Jase

abhiamishra commented 1 year ago

hey @JaseZiv - you can raise a PR. I'll ask @harshkrishna17 what columns he wants to return

harshkrishna17 commented 1 year ago

I'll have a look at this as soon as I can. Thanks!

szfh commented 1 year ago

Someone asked me to help with this function a while ago and I found most of the bugs that FBRef changes had introduced. So I've done the last bit and written a PR to fix them. https://github.com/abhiamishra/ggshakeR/pull/122

  1. Changed stat selection to named stats instead of selecting row numbers, which change because of FBRef data changes.
  2. Added method to de-duplicate some stats that were returned for multiple positions, causing errors.
  3. Changed season default argument to "Last 365 Days Men's Big 5 Leagues, UCL, UEL" to match FBRef data for men's big 5 league players. (this makes the caption wider than before, so some have been split over two lines)
  4. Replaced long |-statements with %in%.
  5. Deleted some old unused code.

All tested for single player and comparison plots with outfield and goalkeeper templates. The Guide to Pizza Plots page should still work without any changes. https://abhiamishra.github.io/ggshakeR/articles/Guide_to_PizzaPlots.html

Rplot2 Rplot01

abhiamishra commented 1 year ago

hi @sfzh - great work; LGTM and I will merge this!