Extracting Freeze Frames

In my first post, I provided a tutorial on importing StatsBomb data in to R using the StatsBombR package. We took that imported data and created a few summary tables for the FA Women’s Super League. Today we are going to take this a step further and extract the shot freeze frame data provided.

You will have noticed last time, we removed the shot.freeze_frame column from our dataset so we could write the CSV summary tables. This was an important step as the shot freeze frame is provided as a nested dataframe. This means that there is a dataframe nested within that cell of the column.

Here is an example of the data nested within the shot.freeze frame_column for a single shot.

115.9, 42.7FALSE15709Megan Walsh1Goalkeeper
103.4, 58.2TRUE15547Melissa Lawley17Right Wing
98.8, 44.0TRUE15613Rinsola Babajide23Center Forward
91.8, 57.7FALSE16392Felicity Gibbons6Left Back
97.8, 51.1FALSE22337Maya Le Tissier5Left Center Back
95.0, 43.1FALSE16383Danique Kerkdijk3Right Center Back
98.7, 32.2FALSE19414Kirsty Barton2Right Back
88.3, 47.3FALSE20034Danielle Buet13Right Center Midfield
88.5, 40.9FALSE31529Léa Le Garrec15Left Center Midfield
87.2, 42.9FALSE23289Emily Simpkins10Center Defensive Midfield
89.1, 51.3FALSE16399Kate Natkiel16Left Midfield
a Table 1. A summary of data extracted from the freeze frame column

As we can see, the freeze frame provides some valuable information on player locations at the time of the shot. From this we could see how many players are in front or behind of the ball, does the player have a clear shot and so on. This was a simple extraction using tidyr::unnest. However, we can run in to problems if there is a null value within the column, where no freeze frame positional data is provided. We will need to filter this row out before we can unnest the data. We would do that as follows:

### I have read in all data previously using StatsBombFreeEvents

FreezeFrameData <- Data %>% 
  filter(type.name == "Shot") %>% 
  select(minute, second, shot.outcome.name, shot.freeze_frame)

FreezeFrame <- FreezeFrameData %>% 
  filter(!map_lgl(shot.freeze_frame, is.null)) %>% 
## Warning: `cols` is now required when using unnest().
## Please use `cols = c(shot.freeze_frame)`

Using purrr and “map_lgl” I can filter out the null values from the shot freeze frame column. From there I can then unnest all the data in to separate rows. Using this filterd and unnested data you can now plot or calculate player density at the time of the shot.

I hope this helps you examine the free StatsBomb data in more detail.

comments powered by Disqus