Search This Blog

Pressure Heat Map In Football Using R

In this blog, the Pressure Heat Map for Tottenham Hotspur  will be created. To do this, two data frames containing Tottenham's shot data will be created. you already remember the dataset from my previous blog Pass Map. The following lines of code(which include the organization of the dataset) will be run:

This last line of code is using the tidyverse library to create a data frame containing the pressure events for Tottenham Hotspur in a soccer match. The clean_df data frame, which was created in the previous code block, is filtered to only include rows with a team.name of "Tottenham Hotspur" and a type.name of "Pressure". The resulting data is stored in a new data frame called Tot_pressure.

This code is using the ggplot2 package from the tidyverse library to create a visualization of the pressure events for Tottenham Hotspur in a UEFA Champions League Final match that took place in the 2018/2019 season.

The ggplot() function is used to specify the data that will be plotted, which in this case is the Tot_pressure data frame that was created in the previous code block.

The annotate_pitch() function is used to draw the soccer pitch on the plot, using dimensions provided by the pitch_statsbomb object and using the specified fill and color values.

The geom_density2d_filled() function is used to create a heat map of the pressure events, using the location.x and location.y columns for the x and y coordinates, respectively. The fill aesthetic is used to color the heat map based on the level of density, and the alpha parameter is used to set the transparency of the fill color. The contour_var parameter is used to specify the variable that will be used to calculate the density.

The scale_x_continuous() and scale_y_continuous() functions are used to set the limits of the x and y axes, respectively.

The labs() function is used to add titles, subtitles, and a caption to the plot, and the theme_minimal() and theme() functions are used to customize the appearance of the plot, including the background color, font family and color, and the visibility of certain elements such as the grid and axis labels. The legend.position parameter is set to "none" to hide the legend.

Running the codes above will yield the following pass map:



Credit: Irfan Alghani Khalid Published in Towards Data Science


0 Comments:

Post a Comment