Contents

1. Visualizing the age of the players vs xBA (expected Batting Average)

2. Visualizing the age of the players vs Barrels%

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ 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(dplyr)
library(ggthemes)
library(ggrepel)

statcast = read.csv('/Users/anuragreddy/Downloads/stats.csv')

1. Age vs xBA

highest_xba <- statcast[statcast$xba == max(statcast$xba), ]

statcast |>
  ggplot(aes(x = player_age, y = xba,label = last_name..first_name)) +
  geom_point(color = 'red') +
  labs(x = "Player Age (2023)", y = "Expected Batting Average (2023)", title = "Age vs Expected Batting Average") +
  geom_hline(yintercept = mean(statcast$xba), color = "blue") +
  annotate("text", x = Inf, y = mean(statcast$xba), 
           label = paste("Mean xBA: ", round(mean(statcast$xba), 3)), 
           vjust = -0.5, hjust = 1) +
  annotate("rect",xmin=22,xmax=33,ymin = mean(statcast$xba),ymax = max(statcast$xba),fill = "black",alpha = 0.3)+
  annotate("text",x=28,y=max(statcast$xba)-0.03,label = "Peak Performance ",color="blue")+
  geom_text(data=highest_xba,aes(label = last_name..first_name),vjust = -0.5)+
  theme_economist()

Interpretation: Players exhibiting a batting average (xBA) below the mean line are considered underperformers. The peak performance for most players typically occurs between the ages of 22 and 33, with xBA values surpassing the average.

Note: Acuña Jr., Ronald has the highest expected batting average in 2023.

2. Age vs barrel_batted_rate

highest_bbr <- statcast[statcast$barrel_batted_rate == max(statcast$barrel_batted_rate), ]

statcast |>
   ggplot(aes(x = player_age, y = barrel_batted_rate)) +
  geom_point(color = 'red') +
  labs(x = "Player Age (2023)", y = "Barrel Batted Rate (2023)", title = "Age vs Barrel Batted Rate") +
  geom_hline(yintercept = 15, color = "blue") +
  annotate("text", x = Inf, y = 15, label = "Elite Barrel Batted Rate line" ,vjust = -0.5, hjust = 1) +
  geom_text(data = highest_bbr,aes(label=last_name..first_name),vjust=-0.5 )+
  theme_economist()

Interpretation: Players who achieve a Barrel Batted Rate of at least 15% are regarded as elite performers in reaching and advancing bases. This level of performance typically occurs between the ages of 22 and 33.

Note: Ohtani, Shohei has the highest Barrel Batted Rate with almost 20 in year 2023.