Batting %>%group_by(yearID) %>%summarize(totalHR =sum(HR)) %>%filter(yearID >=1990) %>%ggplot(aes(x = yearID, y = totalHR, fill =factor(yearID))) +geom_col() +labs(title ="Total Home Runs from 1990-2021", x ="Year", y ="Total HRs") +theme_bw() +theme(text =element_text(family ="serif")) +theme(legend.position ="none")
Pitching %>%group_by(yearID) %>%filter(yearID >=1921, !is.na(ERA)) %>%summarize(avgERA =mean(ERA)) %>%ggplot(aes(x = yearID, y = avgERA)) +geom_line(size =1, color ="dodgerblue") +labs(title ="Average ERA in the Last 100 Years",x ="Year", y ="Average ERA") +theme_bw() +theme(text =element_text(family ="serif"))
Fielding %>%filter(yearID >=2012) %>%ggplot(aes(x =factor(POS), y = DP)) +geom_jitter(alpha =0.4, aes(color =factor(yearID)), position =position_jitter(0.2)) +labs(title ="Number of Double Plays by Position", x ="Position", y ="Double Plays", color ="Year") +theme_bw() +theme(text =element_text(family ="serif"))
Salaries %>%group_by(yearID) %>%summarize(Low =min(salary), Median =median(salary), Mean =mean(salary), High =max(salary)) %>%ggplot(aes(x = yearID)) +geom_ribbon(aes(ymin = Low, ymax = High), fill ="lightblue", color ="black", alpha =0.5) +geom_line(aes(y = Median), color ="black", linetype ="dashed") +geom_line(aes(y = Mean), color ="black", linetype ="dotted") +scale_y_continuous(labels = scales::label_dollar()) +labs(title ="MLB Salary Range Over Time", subtitle ="Median = Dashed Line, Mean = Dotted Line", y ="Salary", x ="Season") +theme_bw() +theme(text =element_text(family ="serif"))
8.2 FanGraphs
fg_update %>%ggplot(aes(x = BB_rate, y = K_rate, label = Team, fill = WAR)) +geom_label(alpha =0.6, size =3, family ="serif") +labs(title ="K% and BB% For Each MLB Team", x ="Walk Rate(%)", y ="Strikeout Rate(%)") +scale_fill_viridis_c() +theme_bw() +theme(text =element_text(family ="serif"))
judge_filtered %>%ggplot(aes(x = EV, LA, color =factor(RBI))) +geom_point(alpha =0.6) +labs(title ="Aaron Judge Batting", x ="Exit Velocity", y ="Launch Angle", color ="RBI") +scale_color_viridis_d() +theme_bw() +theme(text =element_text(family ="serif"))
pl_filtered %>%ggplot(aes(x =factor(Season), y = ERA)) +geom_jitter(alpha =0.6, aes(color = Age),position=position_jitter(0.2)) +labs(title ="Pitchers", x ="Season") +scale_color_viridis_b() +theme_bw() +theme(text =element_text(family ="serif"))