### Install ggshakeR from GitHub Source: https://github.com/abhiamishra/ggshaker/blob/main/README.md Installs the latest version of ggshakeR from GitHub using devtools. ```r devtools::install_github("abhiamishra/ggshakeR") ``` -------------------------------- ### Install devtools package Source: https://github.com/abhiamishra/ggshaker/blob/main/README.md Installs the devtools package, which is required to install ggshakeR from GitHub. ```r install.packages("devtools") ``` -------------------------------- ### plot_passnet example Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_passnet.html Example usage of plot_passnet with Opta data for Arsenal. Wrapped in if (FALSE) to prevent execution during package checks. ```r if (FALSE) { plot <- plot_passnet(data, data_type = "opta", team_name = "Arsenal") plot } ``` -------------------------------- ### plot_shot example with hexbin Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_shot.html Example usage of plot_shot with type = "hexbin", bins = 20, average_location = TRUE, and highlight_goals = FALSE. Wrapped in if (FALSE) to prevent execution during package checks. ```r if (FALSE) { plot <- plot_shot(data, type = "hexbin", bins = 20, average_location = TRUE, highlight_goals = FALSE) } ``` -------------------------------- ### Install ggshakeR version 0.1.2 Source: https://github.com/abhiamishra/ggshaker/blob/main/README.md Re-installs version 0.1.2 of ggshakeR, useful if you need to revert from version 0.2.0. ```r devtools::install_github("abhiamishra/ggshakeR@0.1.2") ``` -------------------------------- ### plot_pizza comparison and single plot examples Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_pizza.html Example usage of plot_pizza for both comparison and single plots. The comparison plot uses player_1 and player_2 with a custom comparison color and black theme. The single plot uses custom colors for possession, attack, and defense with a dark theme. The entire example is wrapped in if (FALSE) to prevent execution during documentation building. ```r if (FALSE) { plot1 <- plot_pizza(data = data, type = "comparison", template = "outfielder", player_1 = "Nicolo Barella", player_2 = "Ilkay Gundogan", season_player_1 = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", season_player_2 = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", color_compare = "lightgreen", theme = "black") plot1 plot2 <- plot_pizza(data = data1, type = "single", template = "outfielder", color_possession = "green", color_attack = "lightblue", season = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", color_defense = "red", theme = "dark") plot2 } ``` -------------------------------- ### Example: plot_passflow with binwidth 30 Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_passflow.html Example usage of plot_passflow wrapped in if(FALSE) to prevent execution during package checks. It creates a passflow plot with binwidth 30 and prints it. ```r if (FALSE) { plot <- plot_passflow(data, binwidth = 30) plot } ``` -------------------------------- ### Example: plot_timeline with Manchester United vs Liverpool Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_timeline.html Example usage wrapped in if (FALSE) to prevent execution. Creates a timeline plot for the 2021 match between Manchester United and Liverpool with specified colors and dark theme. ```r if (FALSE) { plot <- plot_timeline(data = data, match_year = 2021, team_home = "Manchester United", team_away = "Liverpool", color_home = "#e31a1c", color_away = "#980043", theme = "dark") plot } ``` -------------------------------- ### Calculate EPV difference Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_EPV.html Computes the difference between EPVEnd and EPVStart to get the EPV value for events with start and end locations. ```r EPVData <- EPVData %>% mutate(EPV = EPVEnd - EPVStart) ``` -------------------------------- ### plot_sonar example Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_sonar.html Example usage of plot_sonar wrapped in an if (FALSE) block, indicating it is not executed. It creates a plot object and prints it. ```r if (FALSE) { plot <- plot_sonar(data, data_type = "statsbomb") plot } ``` -------------------------------- ### plot_trendline example Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_trendline.html Example usage wrapped in if (FALSE) to prevent execution during package checks. It plots a trendline for Tottenham with specified colors, rolling average of 10, and dark theme. ```R if (FALSE) { plot <- plot_trendline(data = pl, team = "Tottenham", color_xg = "#08519c", color_xga = "#cb181d", rolling_average = 10, theme = "dark") plot } ``` -------------------------------- ### plot_convexhull example with Opta data Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_convexhull.html Example usage wrapped in if (FALSE) to prevent execution during package checks. It creates a convex hull plot with Opta data, blue color, and title 'Team 1', then prints the plot. ```R if (FALSE) { plot <- plot_convexhull(data = data, data_type = "opta", color = "blue", title = "Team 1") plot } ``` -------------------------------- ### Example: calculate_epv with statsbomb data Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/calculate_epv.html Example of using calculate_epv with a test dataframe and type = "statsbomb". The code is wrapped in if (FALSE) to prevent execution during documentation checks. The result is stored in endResult and printed. ```r if (FALSE) { endResult <- calculate_epv(test, type = "statsbomb") endResult } ``` -------------------------------- ### Example: calculate_threat with statsbomb data Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/calculate_threat.html Example usage of calculate_threat with type set to "statsbomb". The code is wrapped in if (FALSE) to prevent execution during package checks. It assigns the result to endResult and prints it. ```r if (FALSE) { endResult <- calculate_threat(test, type = "statsbomb") endResult } ``` -------------------------------- ### calculate_epv(data, type = "opta") Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/calculate_epv.html Documentation for the calculate_epv function, which calculates Expected Possession Value (EPV) for passes, carries, etc. It takes a dataframe with start and end coordinates and a data type indicator, and returns a dataframe. ```APIDOC ## calculate_epv(data, type = "opta") ### Description Calculates Expected Possession Value (EPV) for passes, carries, etc. based on the provided event data. ### Usage calculate_epv(data, type = "opta") ### Arguments - **data** (dataframe) - Required - The dataframe that stores your data. Must contain starting x,y locations and ending x,y locations: `x`, `y`, `finalX`, `finalY`. - **type** (character) - Optional - Indicator for what type of data the eventData. Currently, options include "opta" (default) and "statsbomb". ### Value Returns a dataframe object. ### Examples ```r if (FALSE) { endResult <- calculate_epv(test, type = "statsbomb") endResult } ``` ``` -------------------------------- ### Get player shots with get_player_shots() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Retrieves Mohammed Salah's shot data from Understat using the understatr package. The player_id 1250 corresponds to Salah. ```R shot_data <- get_player_shots(player_id = 1250) # Salah's `player_id` on Understat is `1250` ``` -------------------------------- ### Example: plot_heatmap with hex type Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_heatmap.html Example usage of plot_heatmap with type = "hex". The code is wrapped in if (FALSE) so it is not executed during package checks. It creates a hex binwidth heatmap from touchData and assigns it to plot, then prints it. ```r if (FALSE) { plot <- plot_heatmap(data = touchData, type = "hex") plot } ``` -------------------------------- ### Example: plot_pass with type 'all' and progressive_pass Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_pass.html Example usage of plot_pass. It creates a plot with all passes and progressive passes, then displays it. Wrapped in if (FALSE) to prevent execution during package checks. ```r if (FALSE) { plot <- plot_pass(data, type = "all", progressive_pass = TRUE) plot } ``` -------------------------------- ### Create voronoi diagram with plot_voronoi Source: https://github.com/abhiamishra/ggshaker/blob/main/man/plot_voronoi.Rd Creates a voronoi diagram on a football pitch using the plot_voronoi function. The example sets the point colour to blue and adds a title. The resulting plot object is then printed. ```r plot <- plot_voronoi(data = data, colour = "blue", title = "Team 1") plot ``` -------------------------------- ### plot_voronoi example Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_voronoi.html Example usage of plot_voronoi wrapped in if (FALSE) to prevent execution during package checks. It creates a plot with blue points and title "Team 1". ```R if (FALSE) { plot <- plot_voronoi(data = data, colour = "blue", title = "Team 1") plot } ``` -------------------------------- ### plot_scatter example usage Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_scatter.html Example usage of plot_scatter with a data frame, x and y columns, and a label column. Wrapped in if (FALSE) to prevent execution during package checks. ```r if (FALSE) { plot <- plot_scatter(data, x = "player", y = "age", label = "team") plot } ``` -------------------------------- ### Create a scatter plot with plot_scatter Source: https://github.com/abhiamishra/ggshaker/blob/main/man/plot_scatter.Rd Example usage of the plot_scatter function. It creates a scatter plot using the 'player' column for the x-axis, 'age' for the y-axis, and labels points with the 'team' column. The resulting plot object is then printed. This example is wrapped in \dontrun{} and is not executed during package checks. ```r plot <- plot_scatter(data, x = "player", y = "age", label = "team") plot ``` -------------------------------- ### plot_heatmap Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_heatmap.html Plots various types of heatmaps of starting x and y coordinates: hex binwidth heatmap, density heatmap, and binwidth heatmap. ```APIDOC ## plot_heatmap ### Description This function allows you to plot various types of heatmaps of starting x and y coordinates: hex binwidth heatmap, density heatmap, and binwidth heatmap. ### Usage ```r plot_heatmap( data, type = "", data_type = "statsbomb", binwidth = 20, theme = "" ) ``` ### Arguments - **data** (dataframe) - Required - The dataframe that stores your data. Dataframe must contain at least the following columns: `x`, `y`. - **type** (character) - Optional - Indicates the type of heatmap to plot. "hex" indicates hex bins, "density" indicates density (default), "binwidth" indicates binwidth heatmap pass, and "jdp" indicates a binned heatmap according jdp pitch markings. - **data_type** (character) - Optional - Type of data that is being put in: opta or statsbomb. Default set to "statsbomb". - **binwidth** (numeric) - Optional - Indicates the size of the bin width to construct heatmap for type "binwidth". The same argument name as the underlying call to `geom_bin2d()`. Default set to 20. - **theme** (character) - Optional - Indicates what theme the map must be shown in: dark (default), white, rose, almond. ### Value Returns a ggplot2 object. ### Examples ```r if (FALSE) { plot <- plot_heatmap(data = touchData, type = "hex") plot } ``` ``` -------------------------------- ### Create xG timeline with plot_timeline Source: https://github.com/abhiamishra/ggshaker/blob/main/man/plot_timeline.Rd Example usage of plot_timeline to create an xG timeline chart. The function expects understat event data, a match year, home and away team names, and line colors. The theme parameter accepts 'dark', 'almond', 'rose', or 'white'. The result is a ggplot2 object that can be printed by evaluating the variable. ```r plot <- plot_timeline(data = data, match_year = 2021, team_home = "Manchester United", team_away = "Liverpool", color_home = "#e31a1c", color_away = "#980043", theme = "dark") plot ``` -------------------------------- ### calculate_threat function signature Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/calculate_threat.html Function signature for calculating expected threat (xT) from pass and carry data. The data argument must contain starting and ending coordinates: x, y, finalX, finalY. The type argument indicates the data format, with "opta" as the default and "statsbomb" as an alternative. ```r calculate_threat(data, type = "opta") ``` -------------------------------- ### calculate_epv function usage Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/calculate_epv.html Function signature for calculating expected possession value (EPV). The data argument must contain starting and ending coordinates: x, y, finalX, finalY. The type argument defaults to "opta" but can be set to "statsbomb". ```r calculate_epv(data, type = "opta") ``` -------------------------------- ### Calculate xT difference with mutate() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Exp_Threat.html Computes the difference in xT (xTEnd - xTStart) and stores it in a new column named xT. This value can be used for passes, carries, or any event with a start and end location. Use xTStart/xTEnd for single-occurring events such as take-ons or tackles. ```R xTData <- xTData %>% mutate(xT = xTEnd - xTStart) ``` -------------------------------- ### plot_pass Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_pass.html Documentation for the plot_pass function in the ggshakeR package, including usage, arguments, and examples. ```APIDOC ## plot_pass ### Description This function allows you to plot various types of plots that have passes as some sort of input. Data entered must have columns for which you want to plot with. Compatible with StatsBomb and Opta data. ### Usage ```r plot_pass( data, data_type = "statsbomb", type = "sep", progressive_pass = FALSE, cross = FALSE, shot = FALSE, switch = FALSE, outcome = "all", theme = "dark" ) ``` ### Arguments - **data** (data.frame) - Required - The data frame that stores your passing data. Opta data frame must contain at least the following columns: `x`, `y`, `finalX`, `finalY`. - **data_type** (character) - Optional - Type of data that is being put in: opta or statsbomb. Default set to "statsbomb". - **type** (character) - Optional - Indicates the type of plot to pass. "sep" separates successful and unsuccessful passes. "all" plots all passes on one pitch. Default = "sep". Only available for StatsBomb data. - **progressive_pass** (logical) - Optional - Indicates whether to map out progressive passes. Only available for StatsBomb data. - **cross** (logical) - Optional - Indicates whether to map out crosses. Only available for StatsBomb data. - **shot** (logical) - Optional - Indicates whether to map out shot assists. Only available for StatsBomb data. - **switch** (logical) - Optional - Indicates whether to map out switches of play. Only available for StatsBomb data. - **outcome** (character) - Optional - Indicates whether you want successful ("suc"), unsuccessful ("unsuc"), or all ("all"). Only available for StatsBomb data. - **theme** (character) - Optional - Indicates what theme the map must be shown in: dark (default), white, rose, almond. ### Value Returns a ggplot2 object. ### Examples ```r if (FALSE) { plot <- plot_pass(data, type = "all", progressive_pass = TRUE) plot } ``` ``` -------------------------------- ### Create and display a passflow plot with plot_passflow Source: https://github.com/abhiamishra/ggshaker/blob/main/man/plot_passflow.Rd Example usage of plot_passflow with a custom binwidth of 30. The code is wrapped in \dontrun{} because it requires a pre-existing dataframe named 'data' with pass data columns. The resulting ggplot object is assigned to 'plot' and then printed. ```r plot <- plot_passflow(data, binwidth = 30) plot ``` -------------------------------- ### Load sample Opta data with ggshakeR::SampleEventData Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Loads the sample Opta event data set included in the ggshakeR package for use with plot_passnet(). ```r optadata <- ggshakeR::SampleEventData ``` -------------------------------- ### plot_pizza() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Version_0-2-0.html Documentation for the `plot_pizza()` function, including its parameters and usage. ```APIDOC ## `plot_pizza()` ### Description Plots a pizza chart for player comparison. ### Method Function call ### Endpoint `plot_pizza(data, type, template, color_possession, color_attack, color_defense, color_compare, player_1, player_2, season, season_player_1, season_player_2, theme)` ### Parameters - **data** - Required - The data for the plot. - **type** - Required - The plot type. - **template** - Required - The template to use. - **color_possession** - Optional - Color for possession (renamed from `color_poss`). - **color_attack** - Optional - Color for attack (renamed from `color_att`). - **color_defense** - Optional - Color for defense (renamed from `color_def`). - **color_compare** - Optional - Color for comparison. - **player_1** - Required - First player. - **player_2** - Optional - Second player. - **season** - Optional - Season. - **season_player_1** - Optional - Season for player 1. - **season_player_2** - Optional - Season for player 2. - **theme** - Optional - The theme for the plot. ### Request Example ```r plot_pizza(data = data, type = "pizza", template = "default", color_possession = "blue", color_attack = "red", color_defense = "green", color_compare = "yellow", player_1 = "Player A", player_2 = "Player B", season = 2020, season_player_1 = 2020, season_player_2 = 2020, theme = "dark") ``` ### Response Returns a ggplot object (not specified in source). ``` -------------------------------- ### Create basic voronoi plot with plot_voronoi() Source: https://github.com/abhiamishra/ggshaker/blob/main/vignettes/Guide_to_Pitch_Plots.Rmd Prepares summarized player mean positions from plotting_data and creates a basic voronoi plot. The data must contain x and y columns; the default data_type is "statsbomb". ```r finalData <- plotting_data %>% filter(team.name == "Barcelona") %>% group_by(player.name) %>% summarise_at(vars(x, y, minute), list(name = mean), na.rm = TRUE) %>% na.omit() %>% rename("x" = "x_name") %>% rename("y" = "y_name") ``` ```r plotVoronoi <- plot_voronoi(finalData) plotVoronoi ``` -------------------------------- ### Use highlight_goals and average_location arguments Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Creates a shot map with highlight_goals enabled and average_location disabled. Note that highlight_goals only works for point shot maps. ```R plot <- plot_shot(shot_data, highlight_goals = TRUE, average_location = FALSE) plot ``` -------------------------------- ### Load EPVGrid with ggshakeR Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_EPV.html Loads the ggshakeR package and displays the first rows of the EPVGrid dataframe, which contains the EPV data made public by Laurie Shaw. ```r library(ggshakeR) head(EPVGrid) ``` -------------------------------- ### Load ggshakeR and inspect xTGrid Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Exp_Threat.html Loads the ggshakeR package and displays the first rows of the built-in xTGrid dataframe, which contains Karun Singh's expected threat data. The grid columns correspond to pitch divisions from your own goal (X0) to the opponent's goal (X11). ```R library(ggshakeR) head(xTGrid) ``` -------------------------------- ### Create single player pizza plot with plot_pizza() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_PizzaPlots.html Creates a single-player percentile (pizza) plot using the 'outfielder' template. Requires a scouting report from worldfootballR's fb_player_scouting_report() and the plot_pizza() function. The season filter must match the 'term' in the FBRef scouting period. ```R 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 Men's Big 5 Leagues, UCL, UEL", theme = "dark") pizza ``` -------------------------------- ### Create heatmap with plot_heatmap() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Creates a heatmap using plot_heatmap() with type 'bin' on the selected x and y columns. ```R heat_data <- plotting_data %>% select(x, y) heatPlot <- plot_heatmap(data = heat_data, type = "bin") heatPlot ``` -------------------------------- ### Create custom single player pizza plot with plot_pizza() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_PizzaPlots.html Creates a custom single-player pizza plot by first adding an index column to the scouting report, then selecting specific rows (statistics) and using the 'custom' template. The index column helps identify which stats to include. ```R single_player$index <- 1:nrow(single_player) ## use this column for reference in stat selection ``` ```R single_player <- single_player[c(1,2,3,4,5,6,7,8,9,10,11,12), ] pizza <- plot_pizza(data = single_player, type = "single", template = "custom", color_possession = "#41ab5d", color_attack = "#fec44f", season = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", color_defense = "#de2d26", theme = "dark") pizza ``` -------------------------------- ### Plot a pass sonar with plot_sonar Source: https://github.com/abhiamishra/ggshaker/blob/main/man/plot_sonar.Rd Example usage of plot_sonar with Statsbomb data. The function returns a ggplot2 object that can be assigned to a variable and printed. The data_type argument is set to "statsbomb" (the default). ```r plot <- plot_sonar(data, data_type = "statsbomb") plot ``` -------------------------------- ### calculate_threat() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Version_0-2-0.html Documentation for the `calculate_threat()` function, including its parameters and usage. ```APIDOC ## `calculate_threat()` ### Description Calculates threat based on event data and data type. ### Method Function call ### Endpoint `calculate_threat(data, type)` ### Parameters - **data** - Required - The event data (renamed from `event_data`). - **type** - Required - The data type (renamed from `dataType`). ### Request Example ```r calculate_threat(data = event_data, type = "StatsBomb") ``` ### Response Returns a threat value or object (not specified in source). ``` -------------------------------- ### Load ggshakeR library Source: https://github.com/abhiamishra/ggshaker/blob/main/README.md Loads the ggshakeR package into your R session so you can use its functions. ```r library(ggshakeR) ``` -------------------------------- ### Summarize player positions for voronoi plot Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Prepares data for plot_voronoi() by filtering to a team, grouping by player, and computing mean positions. Requires columns x and y. ```R finalData <- plotting_data %>% filter(team.name == "Barcelona") %>% group_by(player.name) %>% summarise_at(vars(x, y, minute), list(name = mean), na.rm = TRUE) %>% na.omit() %>% rename("x" = "x_name") %>% rename("y" = "y_name") ``` -------------------------------- ### Create density shot map with plot_shot() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Creates a density shot map using plot_shot() and displays it. The data must contain columns X, Y, xG, result, and name. ```R plot <- plot_shot(data, type = "density") plot ``` -------------------------------- ### Plot voronoi diagram with EPV fill Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Repeats the summarization with EPV values and plots a voronoi diagram filled by EPV_Start. Filters out -1 values and renames columns. ```R finalData <- threatData %>% filter(team.name == "Barcelona") %>% group_by(player.name) %>% filter(EPVStart != -1) %>% #Getting rid of -1 as that as how we identify null values #We get the mean and sum of these three columns summarise_at(vars(x, y, EPVStart), list(name = mean, sum), na.rm = TRUE) %>% na.omit() %>% rename("x" = "x_name") %>% rename("y" = "y_name") %>% rename("EPV_Start" = "EPVStart_fn1") #Renaming the relevant columns #Plot voronoi plot plotVoronoi <- plot_voronoi(data = finalData, fill = "EPV_Start", title = "Barcelona Voronoi Diagram") plotVoronoi ``` -------------------------------- ### Calculate EPV with calculate_epv() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_EPV.html Calculates EPV for the plottingData using the statsbomb type, adding EPVStart and EPVEnd columns to the result. ```r EPVData <- calculate_epv(plottingData, type = "statsbomb") ``` -------------------------------- ### Load StatsBomb data for La Liga 2014/15 Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Loads StatsBomb competition and match data for La Liga 2014/15, then retrieves all events and cleans them for plotting. ```R library(StatsBombR) Comp <- FreeCompetitions() %>% filter(competition_id == 11 & season_name == "2014/2015") Matches <- FreeMatches(Comp) StatsBombData <- free_allevents(MatchesDF = Matches, Parallel = TRUE) plotting_data <- allclean(StatsBombData) ``` -------------------------------- ### Plot Opta pass network with plot_passnet() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Creates a pass network plot from the prepared Opta data using plot_passnet() with data_type = "opta", team_name = "Team 1", scale_stat = "EPV", and scale_color = "#fec44f". Assigns the result to passnetPlot and prints it. ```r passnetPlot <- plot_passnet(data = optadata, data_type = "opta", team_name = "Team 1", scale_stat = "EPV", scale_color = "#fec44f") passnetPlot ``` -------------------------------- ### plot_heatmap() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Version_0-2-0.html Documentation for the `plot_heatmap()` function, including its parameters and usage. ```APIDOC ## `plot_heatmap()` ### Description Plots a heatmap of event data. ### Method Function call ### Endpoint `plot_heatmap(data, type, data_type, binwidth, theme)` ### Parameters - **data** - Required - The event data (renamed from `event_data`). - **type** - Required - The plot type. - **data_type** - Required - The data type (e.g., StatsBomb, Opta) (renamed from `dataType`). - **binwidth** - Optional - The bin width for the heatmap (renamed from `bin`). - **theme** - Optional - The theme for the plot (moved to last argument). ### Request Example ```r plot_heatmap(data = event_data, type = "heatmap", data_type = "StatsBomb", binwidth = 1, theme = "dark") ``` ### Response Returns a ggplot object (not specified in source). ``` -------------------------------- ### plot_voronoi Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_voronoi.html Creates a voronoi diagram on a football pitch using Opta or Statsbomb data. Returns a ggplot2 object. ```APIDOC ## plot_voronoi ### Description Creates a voronoi diagram on a football pitch using Opta or Statsbomb data. Returns a ggplot2 object. ### Usage ```r plot_voronoi( data, data_type = "statsbomb", colour = "#E74C3C", fill = "", alpha = 0.4, title = "", theme = "dark" ) ``` ### Arguments - **data** (data.frame) - Required - Dataframe that houses pass data. Must contain at least the columns `x` and `y`. - **data_type** (character) - Optional - Type of data: "opta" or "statsbomb". Default is "statsbomb". - **colour** (character) - Optional - The colour of the points in the voronoi plot. Default is "#E74C3C". - **fill** (character) - Optional - Name of column to add a fill component to the plot. Default is "". - **alpha** (numeric) - Optional - Alpha value for opacity of fill. Default is 0.4. - **title** (character) - Optional - Title of the plot. Default is "". - **theme** (character) - Optional - Theme for the map: "dark" (default), "white", "rose", or "almond". ### Value A ggplot2 object. ### Examples ```r if (FALSE) { plot <- plot_voronoi(data = data, colour = "blue", title = "Team 1") plot } ``` ``` -------------------------------- ### plot_timeline(data, match_year, team_home, team_away, color_home, color_away, theme = "") Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_timeline.html Creates a timeline chart of expected goals (xG) for a match using understat event data. The function takes match details and team colors to generate a ggplot2 object. ```APIDOC ## plot_timeline(data, match_year, team_home, team_away, color_home, color_away, theme = "") ### Description Creates a timeline chart of expected goals (xG) for a match using understat event data. The function takes match details and team colors to generate a ggplot2 object. ### Usage ```r plot_timeline( data, match_year, team_home, team_away, color_home, color_away, theme = "" ) ``` ### Arguments - **data** - Data, for now only compatible with understat data. - **match_year** - the year the match was played. - **team_home** - home team according to data. - **team_away** - away team according to data. - **color_home** - line colour for the home team. - **color_away** - line colour for the away team. - **theme** - Choose from 4 ggplot2 themes -> dark, almond, rose, white. ### Value ggplot2 object of a xG timeline plot ### Examples ```r if (FALSE) { plot <- plot_timeline(data = data, match_year = 2021, team_home = "Manchester United", team_away = "Liverpool", color_home = "#e31a1c", color_away = "#980043", theme = "dark") plot } ``` ``` -------------------------------- ### Comparison pizza plot with plot_pizza (outfielder template) Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_PizzaPlots.html Creates a comparison pizza plot for two outfield players using the 'outfielder' template. Requires specifying both player names and their season strings; the entire player name must be given without accents (e.g., 'Dusan Vlahovic' for Dušan Vlahović). ```R data1 <- fb_player_scouting_report("https://fbref.com/en/players/f586779e/Tammy-Abraham", pos_versus = "primary") data2 <- fb_player_scouting_report("https://fbref.com/en/players/59e6e5bf/Dominic-Calvert-Lewin", pos_versus = "primary") data <- rbind(data1, data2) comp_pizza <- plot_pizza(data = data, type = "comparison", template = "outfielder", player_1 = "Tammy Abraham", player_2 = "Dominic Calvert-Lewin", season_player_1 = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", season_player_2 = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", color_compare = "#41ab5d", theme = "black") comp_pizza ``` -------------------------------- ### calculate_threat(data, type = "opta") Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/calculate_threat.html Function to calculate expected threat (xT) for passes, carries, etc. from event data. ```APIDOC ## calculate_threat(data, type = "opta") ### Description Calculates expected threat (xT) for passes, carries, etc. from event data. ### Usage calculate_threat(data, type = "opta") ### Arguments - **data** (dataframe) - Required - The dataframe that stores your data. Must contain starting x,y locations and ending x,y locations: `x`, `y`, `finalX`, `finalY`. - **type** (character) - Optional - Indicator for what type of data the data. Currently, options include "opta" (default) and "statsbomb". ### Value Returns a dataframe object. ### Examples ```r if (FALSE) { endResult <- calculate_threat(test, type = "statsbomb") endResult } ``` ``` -------------------------------- ### Add player image to pizza plot with magick Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_PizzaPlots.html Adds a player image to the centre of a pizza plot using the magick package. Requires saving the plot as PNG and a player image in the same working directory; the custom function add_image_centre overlays the image and the result is saved with image_write. ```R # install.packages("magick") library(magick) # This is a custom function. There is no need to change the code within the function. Simply run it and then use it as you would any other R function. add_image_centre <- function(plot_path, image_path) { ## Read in plot fig <- image_read(plot_path) fig <- image_resize(fig, "1000x1000") ## Read in image img <- image_read(image_path) img <- image_scale(img, "62x85") ## Overlay image_composite(fig, img, offset = "+471+417") } # Here you use the function to add the player picture to the plot image. imagepl <- add_image_centre(plot_path = "pizza_plot.png", image_path = "tammypic.png") imagepl # Save it as such image_write(imagepl, "addimage.png") ``` -------------------------------- ### Load understatr package Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Loads the understatr package, which is required to fetch Understat data for plot_shot(). ```R library(understatr) ``` -------------------------------- ### plot_trendline(data, team, color_xg, color_xga, rolling_average, theme = "") Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_trendline.html Plots an xG trendline using FBref or StatsBomb data. The input dataframe must contain columns: Date (yyyy-mm-dd), Home_xG, Away_xG, Home, Away. ```APIDOC ## plot_trendline(data, team, color_xg, color_xga, rolling_average, theme = "") ### Description Plots an xG trendline using FBref or StatsBomb data. The input dataframe must contain columns: Date (yyyy-mm-dd), Home_xG, Away_xG, Home, Away. ### Usage ```r plot_trendline(data, team, color_xg, color_xga, rolling_average, theme = "") ``` ### Arguments - **data** - The dataset used. Select the number of matches wanted in the viz beforehand. - **team** - The specific team for the viz. Team must be accurate as per FBref specifications. - **color_xg** - Color for xGoals. - **color_xga** - Color for xGoalsAgainst. - **rolling_average** - The rolling average for the data. - **theme** - Theme from 4 options: dark, almond, rose, white. Default is "". ### Details For best clarity, export plot as a 2000x1000 png. ### Examples ```r if (FALSE) { plot <- plot_trendline(data = pl, team = "Tottenham", color_xg = "#08519c", color_xga = "#cb181d", rolling_average = 10, theme = "dark") plot } ``` ``` -------------------------------- ### Calculate xT with calculate_threat() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Exp_Threat.html Calculates expected threat (xT) for the prepared data using calculate_threat() with type = "statsbomb". The function adds two new columns, xTStart and xTEnd, and places -1 in areas where calculation was not possible. Note that from version 0.2.0 all function arguments are in snake_case. ```R ## NOTE: from version 0.2.0 ALL function arguments are now in snake_case ## 'dataType' is now 'data_type', etc. xTData <- calculate_threat(data = plottingData, type = "statsbomb") ``` -------------------------------- ### Custom stats comparison plot with plot_pizza Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_PizzaPlots.html Builds a comparison pizza plot with custom stats. First add an index column to each player's data, then select the rows corresponding to the desired stats and call plot_pizza with template = "custom". ```R data1 <- fb_player_scouting_report("https://fbref.com/en/players/f586779e/Tammy-Abraham", pos_versus = "primary") data2 <- fb_player_scouting_report("https://fbref.com/en/players/59e6e5bf/Dominic-Calvert-Lewin", pos_versus = "primary") data1$index <- 1:nrow(data1) ## reference for stats selection data2$index <- 1:nrow(data2) ## reference for stats selection ``` ```R data1 <- data1[c(1,2,3,4,5,6,7,8,9,10,11,12), ] data2 <- data2[c(1,2,3,4,5,6,7,8,9,10,11,12), ] data <- rbind(data1, data2) comp_pizza <- plot_pizza(data = data, type = "comparison", template = "custom", player_1 = "Tammy Abraham", player_2 = "Dominic Calvert-Lewin", season_player_1 = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", season_player_2 = "Last 365 Days Men's Big 5 Leagues, UCL, UEL", color_compare = "#41ab5d", theme = "black") comp_pizza ``` -------------------------------- ### plot_shot function usage Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_shot.html Shows the function signature and default arguments for plot_shot. Use this to understand the expected parameters and their defaults. ```r plot_shot( data, type = "", bins = 30, highlight_goals = "", average_location = "", theme = "" ) ``` -------------------------------- ### Map Opta team and player IDs to names with case_when() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Pitch_Plots.html Transforms the sample Opta data set by replacing numeric teamId and playerId values with names using dplyr::case_when(). Required because plot_passnet() expects player and team names, not IDs. ```r optadata <- optadata %>% mutate(teamId = case_when(teamId == 2151 ~ "Team 1", teamId == 3070 ~ "Team 2")) %>% mutate(playerId = case_when(playerId == "1" ~ "Cameron", playerId == "2" ~ "Sahaj", playerId == "3" ~ "Trevor", playerId == "4" ~ "Jolene", playerId == "5" ~ "David", playerId == "6" ~ "Marcus", playerId == "7" ~ "Ryo", playerId == "8" ~ "Anthony", playerId == "9" ~ "Aabid", playerId == "10" ~ "Kylian", playerId == "11" ~ "Harry", playerId == "12" ~ "Victor", playerId == "13" ~ "Jesse", playerId == "14" ~ "Borges", playerId == "15" ~ "Miguel", playerId == "16" ~ "Alex", playerId == "17" ~ "Abdul", playerId == "18" ~ "Eric", playerId == "19" ~ "Marten", playerId == "20" ~ "Robert", playerId == "21" ~ "Lionel", playerId == "22" ~ "Dean", playerId == "23" ~ "Aaron", playerId == "24" ~ "Benjamin", playerId == "25" ~ "Diego", playerId == "26" ~ "Abhishek", playerId == "27" ~ "Samuel", playerId == "28" ~ "Edward", playerId == "29" ~ "Malik", playerId == "30" ~ "Albert", playerId == "31" ~ "Paul", playerId == "32" ~ "Smith", playerId == "33" ~ "Seth", playerId == "34" ~ "Mohammed", playerId == "35" ~ "Eder", playerId == "36" ~ "Adam", playerId == "37" ~ "Harsh", playerId == "38" ~ "Jorge", playerId == "39" ~ "Zak", playerId == "40" ~ "Brandon")) ``` -------------------------------- ### plot_shot(data, type, bins, highlight_goals, average_location, theme) Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/reference/plot_shot.html Plots shot data from Understat as a shot map. Supports different visualization types (hexbin, density, point) and customization options for bin size, goal highlighting, average location lines, and theme. ```APIDOC ## plot_shot(data, type, bins, highlight_goals, average_location, theme) ### Description This function allows for data, that has to be scraped from Understat, to be used for plotting shots. ### Usage ```r plot_shot( data, type = "", bins = 30, highlight_goals = "", average_location = "", theme = "" ) ``` ### Arguments - **data** (dataframe) - Required - Dataframe that houses shot data. Dataframe must contain at least the following columns: X, Y, xG, result, name. - **type** (character) - Optional - Type of showcasing the shotmap: hexbin, density, point (default). - **bins** (numeric) - Optional - Bin size for creating bins. Use this when using hexbin shotmap. The same argument name as the underlying call to `geom_hex()`. Default = 30. - **highlight_goals** (logical) - Optional - To choose to display only the goals in a different color. - **average_location** (logical) - Optional - For removing lines denoting average location of shots if need be. - **theme** (character) - Optional - Theme preferences for display: dark (default), white, rose, almond. ### Value A ggplot2 object. ### Examples ```r if (FALSE) { plot <- plot_shot(data, type = "hexbin", bins = 20, average_location = TRUE, highlight_goals = FALSE) } ``` ``` -------------------------------- ### Create SampleSBData with StatsBombR Source: https://github.com/abhiamishra/ggshaker/blob/main/man/SampleSBData.Rd R code that uses the StatsBombR package to download and clean StatsBomb event data, then renames key columns to x, y, finalX, and finalY. This code was used to generate the SampleSBData dataset. ```R Comp <- FreeCompetitions() %>% filter(competition_id == 11 & season_name == "2014/2015") Matches <- FreeMatches(Comp) StatsBombData <- StatsBombFreeEvents(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") ``` -------------------------------- ### Fetch StatsBomb data for La Liga 2014/15 Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_EPV.html Fetches and cleans StatsBomb open data for La Liga 2014/15 using the StatsBombR package, storing the result in plottingData. ```r library(StatsBombR) Comp <- FreeCompetitions() %>% filter(competition_id == 11 & season_name == "2014/2015") Matches <- FreeMatches(Comp) StatsBombData <- free_allevents(MatchesDF = Matches, Parallel = TRUE) StatsBombData <- allclean(StatsBombData) plottingData <- StatsBombData ``` -------------------------------- ### plot_timeline() Source: https://github.com/abhiamishra/ggshaker/blob/main/docs/articles/Guide_to_Version_0-2-0.html Function signature and parameter changes for plot_timeline(). ```APIDOC ## plot_timeline(data, match_year, team_home, team_away, color_home, color_away, theme) ### Description Creates a timeline plot. Parameter names have been updated for consistency. ### Parameters - **color_home** - Color for home team (renamed from `home_color`). - **color_away** - Color for away team (renamed from `away_color`). ```