Assignment Description

Paragraph explaining what this assignment is all about. next line next line

new paragraph


# Code goes in here 
setwd("C:/Users/Rprut/Downloads/Sports Analytics/NFLBDB2022/")

source("https://raw.githubusercontent.com/ptallon/SportsAnalytics_Fall2026/refs/heads/main/SharedCode.R")

load_packages(c("data.table", "dplyr", "ggplot2", "stringr", "scales", "hms", "gganimate", "gifski", "sf"))


suppressMessages(library(data.table))

y1 <- fread("tracking2018.csv")
y2 <- fread("tracking2019.csv")
y3 <- fread("tracking2020.csv")

tracking_df <- rbind(y1, y2, y3)
rm(y1, y2, y3)
plays <- fread("plays.csv")
players <- fread("players.csv")
games <- fread("games.csv")

plays_df <- left_join(plays, players, by = c("kickerId" = "nflId"))
plays_df <- left_join(plays_df, games, by = c("gameId"))

df <- tracking_df |>
  filter(gameId == 2018123000, playId == 36) |>
  left_join(plays |> select(gameId,playId, absoluteYardlineNumber, playDescription), 
            by = c("gameId", "playId")) |>
  data.frame()

More blurb

  source("https://raw.githubusercontent.com/mlfurman3/gg_field/main/gg_field.R")
ggplot(df) + 
   # Change colors, shapes, and sizes of the points 
  scale_size_manual(values = c(6, 4, 6), guide = "none") +
  scale_shape_manual(values = c(21, 16, 21), guide = "none" ) +
  scale_fill_manual(values = c("orange2", "black", "purple4"), guide = "none" ) +
  scale_color_manual(values = c("black", "#663300", "black"), guide = "none") + 
    gg_field(yardmin = max(-5, min(df$x) -5 ),  yardmax = min(125, max(df$x ) + 5)) + 
  
  #Add points for each player and the ball 
  geom_point(aes(x = x, y = y, shape = team, color = team, size = team, fill = team))