# Filter the data for the pitcher Aidan Krupp
Brian_Foley_data <- data %>%
filter(Pitcher == "Krupp, Aidan")
# Create a detailed table for each pitch
detailed_pitch_table <- Brian_Foley_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 Aidan Krupp")
Detailed Pitch Table for Aidan Krupp
Sinker |
87.28 |
2058.86 |
253.01 |
19.97 |
7.43 |
BallCalled |
4.30 |
2.94 |
5.41 |
8.4 |
Changeup |
85.84 |
2038.63 |
248.16 |
19.69 |
9.22 |
BallCalled |
4.27 |
2.84 |
5.49 |
8.3 |
Changeup |
85.99 |
2014.45 |
250.80 |
18.83 |
7.88 |
StrikeCalled |
4.19 |
2.83 |
5.45 |
8.4 |
Changeup |
85.09 |
1977.81 |
260.66 |
18.18 |
4.33 |
StrikeCalled |
4.11 |
2.85 |
5.50 |
8.7 |
Curveball |
76.05 |
2044.53 |
104.53 |
-12.45 |
4.76 |
BallCalled |
4.14 |
2.76 |
5.39 |
3.5 |
Changeup |
83.89 |
1941.02 |
256.13 |
17.29 |
5.67 |
BallCalled |
4.02 |
3.00 |
5.60 |
8.5 |
Changeup |
86.26 |
2097.19 |
247.29 |
18.82 |
9.28 |
BallCalled |
3.99 |
3.01 |
5.62 |
8.2 |
Changeup |
85.04 |
2124.96 |
250.74 |
18.35 |
7.81 |
BallCalled |
3.96 |
3.16 |
5.80 |
8.4 |
Sinker |
88.81 |
2159.89 |
255.35 |
19.34 |
6.36 |
FoulBallNotFieldable |
4.01 |
3.00 |
5.46 |
8.5 |
Changeup |
85.20 |
2064.70 |
250.09 |
19.89 |
8.52 |
BallCalled |
4.03 |
2.99 |
5.69 |
8.3 |
Changeup |
86.85 |
2109.46 |
258.95 |
20.01 |
5.26 |
BallCalled |
4.27 |
2.90 |
5.32 |
8.6 |
Changeup |
86.32 |
2097.28 |
247.89 |
21.41 |
10.00 |
InPlay |
4.23 |
2.87 |
5.45 |
8.3 |
Changeup |
84.84 |
2088.18 |
258.34 |
20.81 |
5.65 |
BallCalled |
3.91 |
2.97 |
5.58 |
8.6 |
Changeup |
85.96 |
2141.03 |
262.72 |
21.87 |
4.16 |
BallCalled |
4.03 |
3.06 |
5.29 |
8.8 |
Changeup |
85.70 |
2082.04 |
252.10 |
22.51 |
8.62 |
BallCalled |
4.21 |
3.01 |
5.41 |
8.4 |
Changeup |
84.95 |
2009.60 |
255.67 |
17.81 |
5.92 |
StrikeCalled |
3.90 |
2.99 |
5.47 |
8.5 |
Sinker |
86.16 |
2189.87 |
262.83 |
18.66 |
3.70 |
BallCalled |
3.91 |
3.01 |
5.50 |
8.8 |
# 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 %in% c("BallCalled", "BallinDirt")),
Strikes = sum(!PitchCall %in% c("BallCalled", "BallinDirt")), # 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")
## Total number of pitches thrown: 17
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Aidan Krupp")
Summary Pitch Table for Aidan Krupp
Changeup |
76.47% |
13 |
9 |
4 |
69.23% |
30.77% |
85.53 |
2060.49 |
7.10 |
19.65 |
253.81 |
8.5 |
4.09 |
2.96 |
5.51 |
Curveball |
5.88% |
1 |
1 |
0 |
100.00% |
0.00% |
76.05 |
2044.53 |
4.76 |
-12.45 |
104.53 |
3.5 |
4.14 |
2.76 |
5.39 |
Sinker |
17.65% |
3 |
2 |
1 |
66.67% |
33.33% |
87.42 |
2136.21 |
5.83 |
19.32 |
257.06 |
8.6 |
4.07 |
2.98 |
5.46 |
# Calculate maximum fastball velocity
max_fb_velocity <- detailed_pitch_table %>%
filter(AutoPitchType %in% c("Four-Seam", "Sinker", "Cutter")) %>%
summarise(MaxFBVelocity = max(ReleaseSpeed, na.rm = TRUE)) %>%
pull(MaxFBVelocity)
# Display the maximum fastball velocity
cat("Aidan Krupp maximum FB velocity: ", max_fb_velocity, "mph\n")
## Aidan Krupp maximum FB velocity: 88.81 mph
# Prepare data for plotting pitch locations
pitch_location_data <- Brian_Foley_data %>%
select(AutoPitchType, PlateLocHeight, PlateLocSide, PitchCall) %>%
rename(
PitchHeight = PlateLocHeight,
PitchSide = PlateLocSide
) %>%
mutate(
SwingTake = ifelse(PitchCall %in% c("StrikeSwinging", "FoulBall", "FoulBallFieldable", "FoulBallNotFieldable", "InPlay"), "Swing", "Take"),
Chase = ifelse(SwingTake == "Swing" & (PitchSide < -0.85 | PitchSide > 0.85 | 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) +
geom_rect(aes(xmin = -0.5, xmax = 0.5, ymin = 1.75, ymax = 3.25), fill = NA, color = "red", linetype = "solid", size = 1) +
geom_rect(aes(xmin = -0.85, xmax = 0.85, ymin = 1.5, ymax = 3.5), fill = NA, color = "black", linetype = "solid", size = 1) +
geom_rect(aes(xmin = -1.25, xmax = 1.25, ymin = 1.25, ymax = 3.75), fill = NA, color = "gray", linetype = "solid", size = 1) +
scale_x_continuous(limits = c(-2, 2)) +
scale_y_continuous(limits = c(0, 5)) +
coord_fixed(ratio = 1) +
labs(title = "Pitch Locations for Aidan Krupp",
x = "Horizontal Location (feet)",
y = "Vertical Location (feet)",
color = "Swing/Take",
shape = "Chase") +
facet_wrap(~ AutoPitchType) +
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
scale_x_continuous(limits = c(-25, 25)) + # Set horizontal limits to +/- 25 inches
scale_y_continuous(limits = c(-25, 25)) + # Set vertical limits to +/- 25 inches
labs(title = paste("Pitch Movement"),
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")
)
