Giter VIP home page Giter VIP logo

ggshaker's Introduction

Hi, I'm Abhishek Amol Mishra!

👋 About Me

I am a computer science undergrad currently pursuing the fields of AI/ML. I dabble in data, machine learning, and backend development.

Abhishek's GitHub stats

Top Langs

trophy

Powered By Chatalytics:tm:

  • 🔭 I’m currently working on an exciting new project (revealed soon!)
  • 🌱 I’m currently learning machine learning and artifical intelligence
  • 👯 I’m looking to collaborate on data, backend developement, and machine learning
  • 🤔 I’m looking for help with ggshakeR! If you know R, let me know!
  • 💬 Ask me about football, data, and music!
  • 📫 How to reach me: [email protected]
  • 😄 Pronouns: he/him
  • ⚡ Fun fact: Puedo hablar espanol! Habla conmigo y vamos a cambiar el mundo!

ggshaker's People

Contributors

abhiamishra avatar harshkrishna17 avatar rithwikrajendran avatar ryo-n7 avatar szfh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ggshaker's Issues

Plot_trendline error

Hi,

I was running your code for the Trendline plot, but I got the following error:

Error in plot_trendline(data = df, team = "Manchester United", colour_xg = "#08519c", : unused arguments (colour_xg = "#08519c", colour_xga = "#cb181d", roll_avg = 2)

Any help would be much appreciated!

Thanks in advance.

Zakariah

Pass Network Function

New function {plot_passnet} to plot pass networks using Opta and StatsBomb data. Function is done (function argument naming snake_case or camelCase yet to be figured out).

Currently the numbers for the passnet viz are random (numbered 1-11 on the basis of number of passes played). If the function to convert JSON to CSV is completed and the data contains shirt numbers, then the function can be further changed to include them in the viz (personally I think keeping the current numbering format would reduce any potential errors).

remove color palette dependencies & allow for more color customization by the user

continuing on from issue #20 ...

  • extract zissou1 palette: pal <- wes_palette("Zissou1", 10, type = "continuous") and set that as the default, then allow user to input their own color palette list object to use in plot_sonar()
  • plot_passflow: viridis has own copy function in ggplot2 so no need for the {viridis} package... can set version _d as default by extracting color hex codes? also allow user to input their own

[Feature Request]: UEFA-compliance / autotype compliance

Suggest an idea or something that can be improved.

Currently, our functions are compliant to StatsBomb and Opta. UEFA-styled coordinates do exist today, new news for me, and it would be a nice thing to have that implemented.

A nicer thing would if we were able to understand the type of the dataframe automatically,,,,, food for thought!

ggshakeR Gallery New Issue

This is the new issue for the ggshakeR gallery. I'm creating a checklist for all the stuff I think would be nice to have + things to be added.

  • Create website
  • Solve issue with the colour of code blocks in markdown files (used for articles)

Article ideas :-

  • k-means for clustering passes
  • Comet charts + GMM clustering
  • Bumpy chart

Let me know what other articles you'd like to see.

Also, with this having a separate website, I don't think this necessarily has to run concurrent to the updates made to the package. We can just release articles as they are published. Let me know your thoughts.

[Bug]: Possible error in plot_passnet flip logic?

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:

  • LCB Hendrich, RCB Hegering
  • LW Bühl, RW Huth
  • I believe it should be LCM Däbritz and RCM Magull but I'm not 100% sure what their true avg positions were

With flip = TRUE:

  • The center looks wrong (LCB/RCB swap and possibly LCM/RCM swap)

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

  • The wings look wrong (LW/RW swap, and LB/RB swap)

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

Issues with Pizza plot

Hi,

I want to do a pizza plot comparison between two players, but I've got the following error:

Error in strwrap(string) : argument "string" is missing, with no default
In addition: There were 42 warnings (use warnings() to see them)

Any help would be much appreciated.

Zakariah

Web scrapping Fbref for Pizza Chart

When trying to web-scrape player stats from Fbref, I get the following error:

'Error in open.connection(x, "rb") : HTTP error 429'

I have installed the most stable version: v0.1.2: `devtools::install_github("abhiamishra/[email protected]")

Issue has persisted since last week. Unless Fbref has denied web-scrapping of their website, I’m not sure why this has occurred.

Please re-run the template code in your ggshaker webpage/blog and see if this occurs at your end.

Thanks,
Zakariah

Error when plotting, with white plot.

Using the code in the tutorial in the final step i cannot get the final result because of this error:
Error in if (0 <= angle & angle < 90) { : the condition has length > 1

I have little to none knowledge in R, I'm trying to learn it, could you help me?
image

Simplify plot_pass()

plot_pass(), unlike all the other event data functions has too many parameters and only accepts the "statsbomb" data_type. We should simplify the function to make it more in line with the other functions and thus more intuitive for the users

fix globals and other NAMESPACE issues

na.omit is from {stats} and not base... used in plot_passnet()... tbh could just filter NAs in a different way using the imports we already have

otherwise the usual global vars shenanigans that i'll need to add into globals.R

EPV function

Create a function that assigns values to event data using Laurie Shaw's EPV grid. Expected to be very similar to xT function.

possible new dependencies for version 0.2.0

There are a few packages that are required for the new functions in version 0.2.0 to be added to the dependencies list. They are :-

  1. purrr {plot_convexhull}. Mapping a function to a list. Functions required are map() and reduce().
  2. useful {plot_passnet}. Function required is shift.column().
  3. gridExtra {plot_passnet}. Function required is tableGrob().

There are a few more packages that can be removed :-

  1. Rcpp & RcppRoll. Since we already have TTR to calculate the rolling average, we dont require either package.
  2. wesanderson. This is an option as we already have a colour scale package in viridis. Or of course we can just create a manual colour scale where the colours are an option to the user.

Release 0.2.0 checklist

New update that we want to push through.

Key guidelines for the new updates:

  • make package more simplified, reduce clutter and make functions more streamlined:
  • #26
  • #27
  • #21
  • [x ] add R Graph Gallery with charts that do not need a function but would be nice to have: (gallery stuff is separate from pkg dev - Ryo)
  • EPV (Laurie Shaw's method): #25
  • Harsh's passnet: issue
  • include data wrangling function for converting JSON to CSV: issue # ?
  • move to next release
  • Add convex hull + voronoi function: issue # ?
  • include shot maps compatible for Fotmob data: (Do we need this for 0.2.0 or can this wait for a later version? - Ryo)
  • move to next release
  • Get to 80% test coverage AND/OR have at least one test for each function!
  • Make sure everything passes checks (R CMD check, lintr, etc.)

[Bug]: Timeline flow chart

What happened?

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

Code matches the example here: https://github.com/ggshakeR/ggshakeR.github.io/blob/main/gallery/plots/Timeline%20Flow.R

However, the resulting plot is wrong as seen by the screenshot.

Data: 0-1 win.xlsx

image

library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.1.2
#> Warning: package 'ggplot2' was built under R version 4.1.2
#> Warning: package 'tibble' was built under R version 4.1.2
#> Warning: package 'tidyr' was built under R version 4.1.2
#> Warning: package 'readr' was built under R version 4.1.2
#> Warning: package 'dplyr' was built under R version 4.1.2
library(ggtext)
library(ggbraid)
#> Warning: package 'ggbraid' was built under R version 4.1.2
library(ggshakeR)

df <- readxl::read_xlsx("Documents/Football/Coding/Data/Stoke match data/22.23/Blackburn Rovers (a) 27.08.22/0-1 win.xlsx")
#> Error: `path` does not exist: 'Documents/Football/Coding/Data/Stoke match data/22.23/Blackburn Rovers (a) 27.08.22/0-1 win.xlsx'


df <- df %>%
  select(x, y, endX, endY, teamId, minute, type) %>%
  rename("finalX" = "endX", "finalY" = "endY") %>%
  mutate(teamId = case_when(teamId == 96 ~ "Stoke City", teamId == 158 ~ "Blackburn Rovers")) %>%
  filter(type == "Pass")
#> Error in UseMethod("select"): no applicable method for 'select' applied to an object of class "function"

data <- df %>%
  ggshakeR::calculate_threat() %>%
  mutate(xT = xTEnd - xTStart) %>%
  mutate(xT = tidyr::replace_na(xT, 0))
#> Error in ggshakeR::calculate_threat(.): Dataframe has insufficient number of rows and/or you don't have the right amount of columns: `x`, `y`, `finalX`, `finalY`
view(data)

data1 <- data %>%
  filter(teamId == "Stoke City") %>%
  mutate(xT = ifelse(xT > 0, xT, -xT))
#> Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "function"
data2 <- data %>%
  filter(teamId == "Blackburn Rovers") %>%
  mutate(xT = ifelse(xT > 0, xT, -xT))
#> Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "function"


data <- rbind(data1,data2) %>%
  group_by(minute) %>%
  summarise(xT = sum(xT))
#> Error in rbind(data1, data2): object 'data1' not found

spline_int <- as.data.frame(spline(data$minute, data$xT)) %>%
  mutate(teamId = ifelse(y > 0, "Stoke City", "Blackburn Rovers"))
#> Error in data$xT: object of type 'closure' is not subsettable


theme_custom <- function() {
  theme_minimal() +
    theme(plot.background = element_rect(colour = "#14171A", fill = "#14171A"),
          panel.background = element_rect(colour = "#14171A", fill = "#14171A")) +
    theme(plot.title = element_text(colour = "white", size = 16, hjust = 0.5, face = "bold"),
          plot.subtitle = element_markdown(colour = "white", size = 12, hjust = 0.5),
          plot.caption = element_text(colour = "white", size = 10, hjust = 1),
          axis.title.x = element_text(colour = "white", face = "bold", size = 10),
          axis.title.y = element_text(colour = "white", face = "bold", size = 10),
          axis.text.x = element_text(colour = "white", size = 9),
          axis.text.y = element_text(colour = "white", size = 9)) +
    theme(panel.grid.major = element_line(colour = "#525252", size = 0.4, linetype = "dashed"),
          panel.grid.minor = element_line(colour = "#525252", size = 0.4, linetype = "dashed")) +
    theme(panel.grid.major.x = element_line(colour = "#525252", size = 0.4, linetype = "dashed"),
          panel.background = element_blank()) +
    theme(legend.position = "bottom",
          legend.text = element_text(colour = "white"),
          legend.title = element_text(colour = "white"))
}


ggplot(spline_int) +
  geom_braid(aes(x = x, ymin = 0, ymax = y, fill = teamId)) +
  scale_fill_manual(values = c("deepskyblue3", "firebrick3")) +
  geom_line(aes(x = x, y = y), linetype = "longdash", colour = "white") +
  geom_hline(yintercept = 0, colour = "white", linetype = "solid", size = 0.5) +
  ylim(-0.5, 0.5) +
  theme_custom() +
  labs(x = "Minute", y = "xT Difference", 
       title = "Blackburn Rovers vs. Stoke City xT Flow", 
       subtitle = "2022/23 Championship | GW 6",
       fill = "Team") +
  scale_x_continuous(breaks = seq(from = 0, to = 90, by = 10))
#> Error in ggplot(spline_int): object 'spline_int' not found


ggsave("xTFlow.png", bg = "#14171A", width = 2600, height = 1400, units = "px")

fix transition to stringi from stringr text wrapping

for some reason when i swapped the stringr::str_wrap() function with stringi::stri_wrap(), i get different results in the pizza plot axis text, even though stringr::str_wrap() is supposed to be just a wrapper for the {stringi} version...

[Feature Request]: Refresh and Review Old Functions

Suggest an idea or something that can be improved.

In essence, the original functions

  • plot_pass
  • plot_scatter
  • plot_shot
  • plot_passflow

were all created when the current style and quality guidelines were absent. As such, the usage of these plots seems out-of-touch with the new streamlined functionalities.

The job is to review and process these functions and update their aesthetics and maybe, remove or completely rewrite them.

Package check errors

ran devtools::check() and found the following problems:

  • LICENSE needs to be properly labelled in DESCRIPTION
  • some function arguments weren't documented or they weren't updated... or misspelled...
  • add global vars: globals.R
  • edit vignette to eval=FALSE the call to understatr
  • tests are using worldfootballR to grab data but that takes time and we have to add it into the dependencies which is annoying.... >>> going to find a way to save small snippets into data then load those from within the package or just create a snippet >>> i used the {datapasta} package to create a snippet and save data inside the script itself. Also added bigger data into testdata folder in inst directory
  • import specific functions rather than entire packages in the roxygen tags to sidestep duplicate namespace issues
  • update dep on R 3.5.0 due to loading serialized objects (the test files needed for the tests...)
  • warning in plot_timeline() because if-else statement was giving multiple when it needs a singular TRUE/FALSE so wrapped it in any()
  • chuck planning_guide.xlsx into inst so i don't get a NOTE

[Bug]: Pkgdown Website Dependencies Failing

What happened?


ggshakeR version: 0.2.0.99990
R version: 4.0

Brief description of the problem

" * pkgdown: dependencies must be TRUE, FALSE, NA or a list of dependency types "

edits to Github Actions checks

  • check to see how often codecov runs, have it always run for every push (?)
  • update GHA files to CACHE package dependencies (so not waste valuable GHA minutes installing them every single time)
  • find someway so that lintr comments are posted explicitly in the PR thread as people keep ignoring them

Pitch plots

Hi guys, wondered if someone could help me with the pitch plots. Followed all the instructions but guessing this 'NULL' message when I run it.

plot <- plot_shot(data, type = "density")

plot
NULL

Think its something to do with the getting the data part (5 step code on the Tableau link) but not sure what to do differently. It said put in your desired export location but wasn't sure what that meant or what this bit meant (write.csv(data1,"OzilShot.csv", row.names = FALSE). When I put both into R nothing happens so not sure if its meant to haha

Cheers

Add a favicon

Thought it would be nice to add a package favicon (web tab logo) to the website. I've been reading up on the steps to make one and this has been the result.

Couple of things:

image

  1. Confused as to where the logo should be stored and why the logo appears twice on the website README
  2. The package logo should ideally be a hexagon without the background that technically makes it a square image.

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

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


ggshakeR gallery

Creating a gallery of code for visualizations either too simple or too complex!

Current functions

  • KMC
  • GMM
  • UMAP
  • PCA
  • Bumpy Chart
  • Comet chart

remove extraneous dependencies

  • devtools, roxygen2 do not need to be IMPORTED
  • glue should be replaced easily enough with paste() or sprintf() but will need to check with tests to see if the text formatting still works fine (it should though...)
  • remove berryFunctions >>> can be replaced with dplyr/tibble::add_row()
  • also need to think about stringi + stringr >> if there's some way to just use one or the other... or just replace both with base grep/grepl functions
  • try and check other packages that may not be entirely necessary... but not the most pressing issue, if i can reduce the # of deps in above 3 points then it's not as big of a problem so
  • create a dummy file with lots of syntax/formatting issues to test how lintr GHA works

Pizza plot won't plot

Doing a comparison pizza plot and I keep getting an error returned:

Error in if (0 <= angle & angle < 90) { : the condition has length > 1

I think this has to do with how the function is handling vectorized objects

Convex Hull + Voronoi Function

Convex hull function is done bar ironing out some function argument naming stuff (snake_case or camelCase). One new dependency for plot_convexhull is {purrr}.

Voronoi function not yet started. Maybe @abhiamishra would like to do that one?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.