library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(RCurl)
## 
## Attaching package: 'RCurl'
## 
## The following object is masked from 'package:tidyr':
## 
##     complete

For this analysis, I chose a dataset posted by Marley Myrianthopoulos in the Slack channel. It is a breakdown of home runs hit by position and team in MLB’s AL East division over the last five full seasons (2020 had a shortened season due to the pandemic). The question I want answered is if the HRs by the Catcher position have decreased over time. As a casual baseball fan, my feeling has been over the last few years teams have prioritized the defense at the catching position more than the offense and I would expect to see a decrease over time at catcher.

homers <- read.csv("https://raw.githubusercontent.com/Shayaeng/Data607/main/Project2/baseball_hr.csv")

First I will filter out the other positions and lengthen the table to have the year as a value.

homers_long <- homers %>%
  gather(key = "Year", value = "Total_HRs", starts_with("X")) %>%
  mutate(Year = as.numeric(str_extract(Year, "\\d+"))) %>%
  filter(!is.na(Total_HRs) & Position == "C")

Now I will plot the data to see if there was a trend over the last few years.

ggplot(homers_long, aes(x = factor(Year), y = Total_HRs)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  labs(title = "Total Home Runs Across All Teams and Years",
       x = "Year",
       y = "Total Home Runs") +
  theme_minimal()

ggplot(homers_long, aes(x = factor(Year), y = Total_HRs, fill = Team)) +
  geom_bar(stat = "identity") +
  labs(title = "Total Catcher Home Runs Across AL East Teams",
       x = "Year",
       y = "Total Home Runs") +
  theme_minimal()

The first plot does seem to show an overall downward trend (albeit over a very small sample size) starting in 2019. However, by recreating the plot with a team by team breakdown there seems to have been one specific team in both 2019 and 2021 with oversize production from their catchers, NYY and TBR. A quick Google search will turn up that they were both voted as All Stars in those specific season and thus cannot be indicative of league-wide trends.

In conclusion, I would say my hypothesis was wrong and there does not seem to be a trend of lower catcher totals. However, this is not a very large sample size and there is evidence for the theory so it is not enough data to draw conclusions.