# Read the data in
dat <- read.csv("nfl_pass_rush_receive_raw_data.csv")

# Reformat the dates
dates <- dat %>%
    mutate(game_date = as.Date(game_date, format = "%m/%d/%Y"))

# Classify the seasons
seasons <- dates %>%
    mutate(szn = case_when(game_date >= "2019-09-05" & game_date <
        "2020-02-13" ~ "2019", game_date >= "2020-09-10" & game_date <
        "2021-02-07" ~ "2020", game_date >= "2021-09-09" & game_date <
        "2022-02-14" ~ "2021"))
# New dataset only comparing Rams and Chiefs
matchup <- seasons %>%
    filter(team == "LAR" | team == "KAN") %>%
    filter(team == home_team) %>%
    filter(szn == "2019" | szn == "2020" | szn == "2021") %>%
    filter(pass_target_yds > 0) %>%
    rename(Quarterback = player) %>%
    rename(Home_Score = home_score) %>%
    rename(Opponent_Score = vis_score) %>%
    rename(QB_Passing_Yards = pass_target_yds)


matchup2 <- seasons %>%
    filter(team == "LAR" | team == "KAN") %>%
    filter(team == home_team) %>%
    filter(szn == "2019" | szn == "2020" | szn == "2021") %>%
    filter(pass_target_yds > 0) %>%
    rename(Quarterback = player) %>%
    rename(Home_Score = home_score) %>%
    rename(Opponent_Score = vis_score) %>%
    rename(QB_Passing_Yards = pass_target_yds) %>%
    rename(Season = szn) %>%
    filter(Quarterback == "Jared Goff" | Quarterback == "Matthew Stafford" |
        Quarterback == "Patrick Mahomes" | Quarterback == "Matt Moore")
preplot <- ggplot(matchup2, aes(x = team, y = QB_Passing_Yards,
    fill = Quarterback, label = Season)) + geom_bar(stat = "identity") +
    scale_x_discrete("Team") + scale_y_continuous("Total QB Passing Yards") +
    labs(title = "Chiefs (KAN) and Rams (LAR) Quarterback Performance") +
    theme_classic()
ggplotly(preplot)
plot <- ggplot(matchup, aes(x = Home_Score, y = Opponent_Score,
    size = QB_Passing_Yards, colour = team, label = Quarterback)) +
    geom_point(alpha = 0.9, show.legend = FALSE) + facet_wrap(~szn) +
    theme_light() + labs(title = "Comparing Chiefs (KAN) and Rams (LAR) Home Game Matchups") +
    scale_color_hue() + scale_x_continuous("Chiefs/Rams Home Score") +
    scale_y_continuous("Opponent Score")
ggplotly(plot)