# 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
Changeup |
85.39 |
2078.28 |
254.28 |
21.79 |
7.38 |
BallCalled |
4.06 |
2.61 |
6.23 |
8.5 |
Changeup |
85.97 |
2088.63 |
253.34 |
22.36 |
7.91 |
FoulBallNotFieldable |
4.11 |
2.45 |
6.07 |
8.4 |
Changeup |
86.03 |
2042.30 |
256.37 |
22.00 |
6.59 |
BallCalled |
4.03 |
2.55 |
6.21 |
8.5 |
Changeup |
86.32 |
2143.93 |
257.20 |
22.50 |
6.36 |
BallCalled |
4.04 |
2.66 |
6.19 |
8.6 |
Changeup |
84.81 |
2015.87 |
254.05 |
22.64 |
7.73 |
BallCalled |
3.87 |
2.58 |
6.38 |
8.5 |
Curveball |
74.51 |
2159.11 |
99.35 |
-12.94 |
3.76 |
BallCalled |
3.83 |
2.52 |
6.11 |
3.3 |
Sinker |
87.33 |
2076.14 |
253.24 |
21.10 |
7.57 |
FoulBallNotFieldable |
3.97 |
2.51 |
6.15 |
8.4 |
Sinker |
87.34 |
2101.05 |
258.65 |
23.69 |
5.98 |
BallCalled |
4.02 |
2.56 |
6.19 |
8.6 |
Sinker |
88.03 |
2134.64 |
258.64 |
21.59 |
5.54 |
BallCalled |
3.88 |
2.62 |
6.23 |
8.6 |
Changeup |
87.27 |
2070.95 |
259.64 |
21.66 |
5.18 |
StrikeCalled |
3.86 |
2.71 |
6.35 |
8.7 |
Changeup |
86.56 |
2051.47 |
247.39 |
21.78 |
10.32 |
InPlay |
3.95 |
2.59 |
6.24 |
8.2 |
Changeup |
85.43 |
2085.31 |
255.85 |
21.13 |
6.49 |
BallCalled |
3.95 |
2.58 |
6.33 |
8.5 |
Changeup |
85.99 |
2098.58 |
258.55 |
23.10 |
5.86 |
BallCalled |
4.04 |
2.52 |
5.99 |
8.6 |
Changeup |
85.20 |
2145.19 |
257.81 |
24.16 |
6.46 |
StrikeCalled |
3.95 |
2.51 |
6.12 |
8.6 |
Changeup |
86.13 |
2125.03 |
253.52 |
22.62 |
7.84 |
BallCalled |
3.97 |
2.56 |
6.29 |
8.5 |
Changeup |
85.73 |
2131.00 |
256.92 |
22.85 |
6.50 |
FoulBallNotFieldable |
3.94 |
2.63 |
6.37 |
8.6 |
Changeup |
87.47 |
2076.29 |
261.87 |
23.33 |
4.55 |
BallCalled |
3.95 |
2.62 |
6.03 |
8.7 |
Changeup |
86.03 |
2076.28 |
256.11 |
21.83 |
6.69 |
BallCalled |
3.85 |
2.58 |
6.54 |
8.5 |
Curveball |
75.29 |
2076.78 |
72.60 |
-8.91 |
-1.26 |
BallCalled |
3.55 |
2.65 |
6.30 |
2.4 |
Sinker |
87.23 |
2123.11 |
252.26 |
22.52 |
8.44 |
FoulBallNotFieldable |
3.89 |
2.74 |
6.15 |
8.4 |
Sinker |
86.00 |
2119.89 |
266.14 |
21.65 |
2.76 |
InPlay |
3.96 |
2.67 |
6.36 |
8.9 |
Changeup |
82.92 |
2070.07 |
250.31 |
19.30 |
8.29 |
StrikeCalled |
3.76 |
2.75 |
6.36 |
8.3 |
Curveball |
76.27 |
2060.92 |
45.52 |
-7.30 |
-5.63 |
FoulBallNotFieldable |
3.60 |
2.61 |
6.24 |
1.5 |
Changeup |
86.42 |
2078.46 |
263.01 |
19.26 |
3.81 |
InPlay |
3.73 |
2.77 |
6.16 |
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 == "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")
## Total number of pitches thrown: 24
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Aidan Krupp")
Summary Pitch Table for Aidan Krupp
Changeup |
66.67% |
16 |
9 |
7 |
56.25% |
43.75% |
85.85 |
2086.10 |
6.75 |
22.02 |
256.01 |
8.5 |
3.94 |
2.60 |
6.24 |
Curveball |
12.50% |
3 |
2 |
1 |
66.67% |
33.33% |
75.36 |
2098.94 |
-1.04 |
-9.72 |
72.49 |
2.4 |
3.66 |
2.59 |
6.22 |
Sinker |
20.83% |
5 |
2 |
3 |
40.00% |
60.00% |
87.19 |
2110.97 |
6.06 |
22.11 |
257.79 |
8.6 |
3.94 |
2.62 |
6.22 |
# 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("Aidan Krupp maximum FB velocity: ", max_fb_velocity, "mph\n")
## Aidan Krupp maximum FB velocity: 88.03 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", "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) +
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.75, xmax = 0.75, 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")
)
