Search This Blog

Shots Map in football using R

In this blog, the shot map for Tottenham Hotspur and Liverpool will be created, but with the shots generated by each club plotted on different coordinates. To do this, two data frames containing Liverpool and 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:

The last two lines of code create two data frames containing shot data for Liverpool and Tottenham Hotspur, respectively. The filter() function is used to select only rows with a type.name of "Shot" and a team.name of either "Liverpool" or "Tottenham Hotspur". The select() function is used to select only certain columns from the data. The resulting data frames are stored in the objects Liv_shot and Tot_shot, respectively.

This code is using the ggplot2 package from the tidyverse library to create a visualization of the shots taken by Liverpool and Tottenham Hotspur in a UEFA Champions League Final match that took place in the 2018/2019 season.

The ggplot() function is used to create a new plot, and 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_point() function is used to plot the locations of the shots taken by Liverpool and Tottenham Hotspur, using the Liv_shot and Tot_shot data frames, respectively. The size aesthetic is used to scale the size of the points based on the shot.statsbomb_xg column, which indicates the expected goals value of the shot. The color parameter is used to specify the color of the points.

The labs() function is used to add titles, subtitles, and a caption to the plot, and the theme() function is 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