library(tidyverse)
library(StatsBombR)
mwc <- FreeCompetitions() |>
filter(competition_id == "43" & season_id == "106") |>
FreeMatches() |>
free_allevents() |>
allclean()
mwc_shots <- mwc |>
filter(type.name == "Shot",
shot.type.name == "Open Play",
team.name == possession_team.name) |>
janitor::remove_empty() |>
select(possession_team.name, player.name, position.name, player.name.GK,
period, minute, second, duration, under_pressure,
play_pattern.name, shot.technique.name, shot.body_part.name, shot.outcome.name,
location.x, location.y, location.x.GK, location.y.GK,
DistToGoal, DistToKeeper, AngleToGoal,AngleToKeeper, AngleDeviation,
avevelocity, DistSGK, density.incone,
AttackersBehindBall:InCone.GK, TimeInPoss, TimeToPossEnd) |>
mutate(InCone.GK = ifelse(InCone.GK > 0, 1, InCone.GK),
under_pressure = if_else(is.na(under_pressure), FALSE, under_pressure),
goal = as.factor(if_else(shot.outcome.name == "Goal", 1, 0))) |>
janitor::clean_names()