library(readr)
library(dplyr)
library(devtools)
shots <- read_csv('shots_1549727.csv')
glimpse(shots)
#> Rows: 22
#> Columns: 14
#> $ season_id <dbl> 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021~
#> $ game_id <dbl> 1549727, 1549727, 1549727, 1549727, 1549727, 1549727~
#> $ period_id <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2~
#> $ expanded_minute <dbl> 5, 7, 19, 19, 28, 32, 34, 38, 40, 49, 50, 51, 57, 58~
#> $ second <dbl> 7, 38, 22, 28, 15, 37, 39, 40, 33, 37, 11, 2, 43, 42~
#> $ team_name <chr> "Southampton", "Southampton", "West Ham", "West Ham"~
#> $ player_name <chr> "Oriol Romeu", "Mohamed Elyounoussi", "Craig Dawson"~
#> $ type_name <chr> "MissedShots", "Goal", "SavedShot", "SavedShot", "Sa~
#> $ outcome_type_name <chr> "Successful", "Successful", "Successful", "Successfu~
#> $ is_shot <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE~
#> $ x <dbl> 75.4, 81.1, 95.3, 74.1, 87.3, 85.3, 72.4, 80.9, 96.9~
#> $ y <dbl> 44.7, 52.4, 49.7, 64.3, 82.4, 47.2, 52.8, 55.5, 69.7~
#> $ goal_mouth_y <dbl> 40.2, 47.1, 52.1, 48.6, 47.1, 50.8, 50.6, 47.8, 1.5,~
#> $ goal_mouth_z <dbl> 30.6, 9.5, 11.1, 19.0, 19.0, 3.8, 4.4, 0.6, 4.2, 1.3~
source_url('https://raw.githubusercontent.com/larsmaurath/keine-mathematik/master/content/data/standardize_coordinates.R')
#> i SHA-1 hash of file is 98865bbe8da988de43ee53cc22edde76728a6641
shots_standardized <- shots %>%
standardize_opta_x(cols = 'x') %>%
standardize_opta_y(cols = c('y', 'goal_mouth_y')) %>%
standardize_opta_z(cols = 'goal_mouth_z')
glimpse(shots_standardized)
#> Rows: 22
#> Columns: 14
#> $ season_id <dbl> 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021~
#> $ game_id <dbl> 1549727, 1549727, 1549727, 1549727, 1549727, 1549727~
#> $ period_id <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2~
#> $ expanded_minute <dbl> 5, 7, 19, 19, 28, 32, 34, 38, 40, 49, 50, 51, 57, 58~
#> $ second <dbl> 7, 38, 22, 28, 15, 37, 39, 40, 33, 37, 11, 2, 43, 42~
#> $ team_name <chr> "Southampton", "Southampton", "West Ham", "West Ham"~
#> $ player_name <chr> "Oriol Romeu", "Mohamed Elyounoussi", "Craig Dawson"~
#> $ type_name <chr> "MissedShots", "Goal", "SavedShot", "SavedShot", "Sa~
#> $ outcome_type_name <chr> "Successful", "Successful", "Successful", "Successfu~
#> $ is_shot <lgl> TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE~
#> $ x <dbl> 80.20909, 86.42727, 100.06500, 78.79091, 92.73556, 9~
#> $ y <dbl> 30.32212, 35.83000, 33.77125, 43.97536, 56.03200, 31~
#> $ goal_mouth_y <dbl> 27.19939, 31.78875, 35.60125, 32.93250, 31.78875, 34~
#> $ goal_mouth_z <dbl> 1.96484211, 0.61000000, 0.71273684, 1.22000000, 1.22~Created on 2022-03-29 by the reprex package (v2.0.1)
You can look through shots on Fotmob as a visual check. Goal coordinates are now in meters, so a shot with
goal_mouth_z<=2.44is below the crossbar. A shot withgoal_mouth_y>=34+7.32/2andgoal_mouth_y<=34-7.32/2is in the width of the frame.