knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(knitr)
# Load the data
Keene614 <- read_excel("C:/Users/Franco Castagliuolo/OneDrive - Bentley University/Neers 24/Pitchers/Keene614/Keene614.xlsx")
# Filter the data for the pitcher Adams
Adams_data <- Keene614 %>%
filter(Pitcher == "Adams, Brandon")
# Create a detailed table for each pitch
detailed_pitch_table <- Adams_data %>%
select(AutoPitchType, RelSpeed, SpinRate, SpinAxis, HorzBreak, InducedVertBreak, PitchCall, RelHeight, RelSide, Extension) %>%
rename(
ReleaseSpeed = RelSpeed,
Tilt = SpinAxis,
HorizontalBreak = HorzBreak,
InducedVerticalBreak = InducedVertBreak,
ReleaseHeight = RelHeight,
ReleaseSide = RelSide
) %>%
mutate(
ReleaseSpeed = round(ReleaseSpeed, 2),
SpinRate = round(SpinRate, 2),
Tilt = round(Tilt, 2),
HorizontalBreak = round(HorizontalBreak, 2),
InducedVerticalBreak = round(InducedVerticalBreak, 2),
ReleaseHeight = round(ReleaseHeight, 2),
ReleaseSide = round(ReleaseSide, 2),
Extension = round(Extension, 2),
ClockTilt = round((Tilt / 30) %% 12, 1) # Interpret Tilt as clock face
)
# Display the detailed table
knitr::kable(detailed_pitch_table, caption = "Detailed Pitch Table for Adams")
Detailed Pitch Table for Adams
Four-Seam |
88.94 |
2148.00 |
209.49 |
12.02 |
22.43 |
BallCalled |
5.57 |
2.39 |
7.24 |
7.0 |
Four-Seam |
88.69 |
2164.82 |
212.26 |
12.83 |
21.56 |
FoulBallNotFieldable |
5.59 |
2.32 |
7.28 |
7.1 |
Four-Seam |
89.69 |
2265.22 |
206.78 |
10.78 |
22.63 |
StrikeSwinging |
5.66 |
2.26 |
7.17 |
6.9 |
Four-Seam |
89.79 |
2228.29 |
209.21 |
12.10 |
22.93 |
InPlay |
5.58 |
2.23 |
7.09 |
7.0 |
Curveball |
77.26 |
2332.31 |
66.27 |
-11.03 |
-3.43 |
InPlay |
5.45 |
2.43 |
6.62 |
2.2 |
Four-Seam |
89.74 |
2163.43 |
207.21 |
11.11 |
22.75 |
StrikeSwinging |
5.65 |
2.31 |
7.13 |
6.9 |
Changeup |
80.98 |
1978.35 |
244.57 |
16.57 |
9.22 |
BallCalled |
5.31 |
2.63 |
6.93 |
8.2 |
Changeup |
82.47 |
2102.91 |
238.56 |
15.67 |
10.85 |
StrikeSwinging |
5.21 |
2.56 |
7.01 |
8.0 |
Four-Seam |
90.37 |
2256.63 |
211.77 |
12.77 |
21.76 |
StrikeSwinging |
5.56 |
2.53 |
6.76 |
7.1 |
Changeup |
81.97 |
2000.54 |
245.01 |
17.35 |
9.36 |
StrikeSwinging |
5.34 |
2.48 |
6.95 |
8.2 |
Changeup |
82.59 |
2075.84 |
245.32 |
17.73 |
9.42 |
StrikeSwinging |
5.34 |
2.61 |
6.92 |
8.2 |
Four-Seam |
89.31 |
2271.68 |
213.73 |
13.75 |
21.73 |
BallCalled |
5.55 |
2.49 |
6.94 |
7.1 |
Four-Seam |
90.83 |
2256.15 |
207.48 |
10.81 |
21.88 |
BallCalled |
5.61 |
2.14 |
6.83 |
6.9 |
Changeup |
82.72 |
2106.17 |
243.33 |
16.65 |
9.52 |
FoulBallNotFieldable |
5.31 |
2.63 |
7.04 |
8.1 |
Changeup |
82.44 |
2065.19 |
250.72 |
17.02 |
7.09 |
FoulBallNotFieldable |
5.21 |
2.49 |
6.89 |
8.4 |
Four-Seam |
90.35 |
2219.98 |
207.45 |
10.37 |
21.04 |
HitByPitch |
5.62 |
1.92 |
7.24 |
6.9 |
Four-Seam |
88.62 |
2169.01 |
212.39 |
11.77 |
19.57 |
StrikeCalled |
5.48 |
2.36 |
7.19 |
7.1 |
Four-Seam |
89.19 |
2151.98 |
210.97 |
10.91 |
19.21 |
BallCalled |
5.54 |
2.19 |
7.25 |
7.0 |
Sinker |
89.33 |
2150.34 |
231.93 |
14.84 |
12.70 |
FoulBallNotFieldable |
5.35 |
2.22 |
7.28 |
7.7 |
Four-Seam |
89.49 |
2146.05 |
212.37 |
12.13 |
20.21 |
InPlay |
5.48 |
2.29 |
7.16 |
7.1 |
Four-Seam |
87.46 |
2093.66 |
201.67 |
7.40 |
19.78 |
InPlay |
5.41 |
2.16 |
7.43 |
6.7 |
Four-Seam |
89.15 |
2109.23 |
197.81 |
6.55 |
21.49 |
BallCalled |
5.59 |
2.19 |
7.50 |
6.6 |
Sinker |
87.66 |
2116.01 |
218.37 |
13.30 |
18.00 |
StrikeCalled |
5.43 |
2.08 |
7.33 |
7.3 |
Four-Seam |
87.92 |
2065.02 |
214.02 |
12.29 |
19.37 |
FoulBallNotFieldable |
5.55 |
2.08 |
7.19 |
7.1 |
Slider |
77.68 |
2273.04 |
85.92 |
-7.25 |
0.83 |
BallCalled |
5.33 |
2.29 |
6.41 |
2.9 |
Changeup |
81.01 |
1979.75 |
234.97 |
14.22 |
11.18 |
FoulBallNotFieldable |
5.20 |
2.41 |
7.34 |
7.8 |
Curveball |
75.94 |
2228.99 |
55.42 |
-8.33 |
-4.28 |
StrikeSwinging |
5.37 |
2.38 |
6.57 |
1.8 |
Four-Seam |
87.51 |
2158.88 |
217.64 |
12.98 |
17.91 |
StrikeSwinging |
5.50 |
2.43 |
7.25 |
7.3 |
Four-Seam |
89.14 |
2204.17 |
214.17 |
12.72 |
19.79 |
FoulBallNotFieldable |
5.42 |
2.29 |
7.18 |
7.1 |
Changeup |
80.41 |
1960.42 |
239.95 |
13.85 |
9.25 |
BallCalled |
5.15 |
2.57 |
7.17 |
8.0 |
Curveball |
76.06 |
2271.91 |
68.55 |
-7.33 |
-1.53 |
BallCalled |
5.33 |
2.29 |
6.58 |
2.3 |
Four-Seam |
89.02 |
2093.21 |
205.62 |
9.39 |
20.63 |
FoulBallNotFieldable |
5.39 |
2.29 |
7.13 |
6.9 |
Changeup |
81.24 |
1869.27 |
244.01 |
17.23 |
9.60 |
InPlay |
5.20 |
2.57 |
7.21 |
8.1 |
Sinker |
87.01 |
2079.60 |
232.92 |
15.93 |
13.24 |
BallCalled |
5.42 |
2.33 |
7.34 |
7.8 |
Sinker |
88.31 |
2093.16 |
228.06 |
14.69 |
14.34 |
InPlay |
5.40 |
2.29 |
7.21 |
7.6 |
# Calculate the total number of pitches
total_pitches <- nrow(detailed_pitch_table)
# Create a summary table
pitch_summary <- detailed_pitch_table %>%
group_by(AutoPitchType) %>%
summarise(
TotalPitches = n(),
Usage = sprintf("%.2f%%", n() / total_pitches * 100),
Balls = sum(PitchCall == "BallCalled"),
Strikes = sum(PitchCall != "BallCalled"), # Count everything not a ball as a strike
BallPercentage = sprintf('%.2f%%', Balls / TotalPitches * 100),
StrikePercentage = sprintf('%.2f%%', Strikes / TotalPitches * 100),
AvgVelocity = round(mean(ReleaseSpeed, na.rm = TRUE), 2),
AvgSpinRate = round(mean(SpinRate, na.rm = TRUE), 2),
AvgInducedVertBreak = round(mean(InducedVerticalBreak, na.rm = TRUE), 2),
AvgHorzBreak = round(mean(HorizontalBreak, na.rm = TRUE), 2),
AvgTilt = round(mean(Tilt, na.rm = TRUE), 2),
AvgClockTilt = round(mean(ClockTilt, na.rm = TRUE), 1), # Clock face interpretation
AvgReleaseHeight = round(mean(ReleaseHeight, na.rm = TRUE), 2),
AvgReleaseSide = round(mean(ReleaseSide, na.rm = TRUE), 2),
AvgExtension = round(mean(Extension, na.rm = TRUE), 2)
) %>%
select(AutoPitchType, Usage, everything())
# Display the total number of pitches
cat("Total number of pitches thrown: ", total_pitches, "\n\n")
## Total number of pitches thrown: 35
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Adams")
Summary Pitch Table for Adams
Changeup |
25.71% |
9 |
2 |
7 |
22.22% |
77.78% |
81.76 |
2015.38 |
9.50 |
16.25 |
242.94 |
8.1 |
5.25 |
2.55 |
7.05 |
Curveball |
8.57% |
3 |
1 |
2 |
33.33% |
66.67% |
76.42 |
2277.74 |
-3.08 |
-8.90 |
63.41 |
2.1 |
5.38 |
2.37 |
6.59 |
Four-Seam |
51.43% |
18 |
5 |
13 |
27.78% |
72.22% |
89.18 |
2175.86 |
20.93 |
11.26 |
209.56 |
7.0 |
5.54 |
2.27 |
7.16 |
Sinker |
11.43% |
4 |
1 |
3 |
25.00% |
75.00% |
88.08 |
2109.78 |
14.57 |
14.69 |
227.82 |
7.6 |
5.40 |
2.23 |
7.29 |
Slider |
2.86% |
1 |
1 |
0 |
100.00% |
0.00% |
77.68 |
2273.04 |
0.83 |
-7.25 |
85.92 |
2.9 |
5.33 |
2.29 |
6.41 |
# Calculate maximum fastball velocity
max_fb_velocity <- detailed_pitch_table %>%
filter(AutoPitchType %in% c("Four-Seam", "Two-Seam", "Sinker", "Cutter")) %>%
summarise(MaxFBVelocity = max(ReleaseSpeed, na.rm = TRUE)) %>%
pull(MaxFBVelocity)
# Display the maximum fastball velocity
cat("Adams maximum FB velocity: ", max_fb_velocity, "mph\n")
## Adams maximum FB velocity: 90.83 mph
# Prepare data for plotting pitch locations
pitch_location_data <- Adams_data %>%
select(AutoPitchType, PlateLocHeight, PlateLocSide, PitchCall) %>%
rename(
PitchHeight = PlateLocHeight,
PitchSide = PlateLocSide
) %>%
mutate(
SwingTake = ifelse(PitchCall %in% c("StrikeSwinging", "FoulBallNonSwinging", "FoulBallFieldable", "FoulBallNotFieldable", "InPlay"), "Swing", "Take"),
Chase = ifelse(SwingTake == "Swing" & (PitchSide < -0.75 | PitchSide > 0.75 | PitchHeight < 1.5 | PitchHeight > 3.5), "Chase", "Non-Chase")
)
# Create the scatter plot with specified strike zone boxes
ggplot(pitch_location_data, aes(x = PitchSide, y = PitchHeight, color = SwingTake, shape = Chase)) +
geom_point(size = 3) + # Increase point size
geom_rect(aes(xmin = -0.5, xmax = 0.5, ymin = 1.75, ymax = 3.25), fill = NA, color = "red", linetype = "solid", size = 1) + # Red box
geom_rect(aes(xmin = -0.75, xmax = 0.75, ymin = 1.5, ymax = 3.5), fill = NA, color = "black", linetype = "solid", size = 1) + # Black box
geom_rect(aes(xmin = -1.25, xmax = 1.25, ymin = 1.25, ymax = 3.75), fill = NA, color = "gray", linetype = "solid", size = 1) + # Gray box
scale_x_continuous(limits = c(-2, 2)) +
scale_y_continuous(limits = c(0, 5)) +
coord_fixed(ratio = 1) + # Adjust ratio to shrink vertical distance
labs(title = "Pitch Locations for Adams",
x = "Horizontal Location (feet)",
y = "Vertical Location (feet)",
color = "Swing/Take",
shape = "Chase") +
facet_wrap(~ AutoPitchType) + # Create individual graphs for each pitch type
geom_text(aes(x = -1.75, y = 5, label = "RHH"), color = "black", size = 3, hjust = 0) + # Label for RHH
geom_text(aes(x = 1.75, y = 5, label = "LHH"), color = "black", size = 3, hjust = 1) + # Label for LHH
theme_minimal() +
theme(
legend.position = "right",
panel.grid.major = element_line(color = "grey80"),
panel.grid.minor = element_line(color = "grey90"),
axis.text = element_text(color = "black"),
axis.title = element_text(color = "black"),
plot.title = element_text(color = "black"),
legend.background = element_rect(fill = "white", color = NA),
legend.key = element_rect(fill = "white", color = NA),
legend.text = element_text(color = "black"),
legend.title = element_text(color = "black")
)

# Create the scatter plot for horizontal and vertical breaks
ggplot(detailed_pitch_table, aes(x = HorizontalBreak, y = InducedVerticalBreak, color = AutoPitchType)) +
geom_point(size = 3) + # Increase point size
labs(title = "Pitch Movement for Adams",
x = "Horizontal Break (inches)",
y = "Induced Vertical Break (inches)",
color = "Pitch Type") +
theme_minimal() +
theme(
legend.position = "right",
panel.grid.major = element_line(color = "grey80"),
panel.grid.minor = element_line(color = "grey90"),
axis.text = element_text(color = "black"),
axis.title = element_text(color = "black"),
plot.title = element_text(color = "black"),
legend.background = element_rect(fill = "white", color = NA),
legend.key = element_rect(fill = "white", color = NA),
legend.text = element_text(color = "black"),
legend.title = element_text(color = "black")
)
