# 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 |
86.38 |
2023.39 |
260.99 |
23.29 |
4.99 |
FoulBallNotFieldable |
4.26 |
2.93 |
5.22 |
8.7 |
Curveball |
76.06 |
1808.89 |
41.76 |
-5.39 |
-4.19 |
InPlay |
4.14 |
2.83 |
4.81 |
1.4 |
Changeup |
86.94 |
2002.16 |
259.16 |
22.47 |
5.59 |
StrikeCalled |
4.04 |
2.82 |
5.56 |
8.6 |
Changeup |
86.84 |
2010.22 |
261.89 |
22.13 |
4.46 |
BallCalled |
4.12 |
2.91 |
5.31 |
8.7 |
Changeup |
84.74 |
2008.90 |
276.79 |
22.28 |
-1.31 |
BallCalled |
4.12 |
3.09 |
5.29 |
9.2 |
Changeup |
86.59 |
2076.88 |
265.87 |
22.96 |
3.01 |
StrikeCalled |
4.12 |
2.96 |
5.51 |
8.9 |
Changeup |
87.54 |
2060.50 |
266.26 |
22.97 |
2.81 |
InPlay |
4.23 |
2.86 |
5.37 |
8.9 |
Curveball |
77.82 |
2045.81 |
68.69 |
-4.23 |
-0.07 |
StrikeSwinging |
4.10 |
2.86 |
4.90 |
2.3 |
Changeup |
85.45 |
1975.10 |
268.84 |
21.23 |
1.80 |
BallCalled |
4.15 |
2.86 |
5.58 |
9.0 |
Changeup |
86.06 |
2083.26 |
266.47 |
23.33 |
2.79 |
StrikeSwinging |
4.03 |
2.99 |
5.51 |
8.9 |
Curveball |
76.93 |
1984.97 |
59.62 |
-6.02 |
-1.83 |
FoulBallFieldable |
4.10 |
2.88 |
4.96 |
2.0 |
Sinker |
87.67 |
2149.23 |
265.71 |
23.28 |
3.08 |
FoulBallNotFieldable |
4.15 |
2.67 |
5.60 |
8.9 |
Curveball |
77.60 |
1904.20 |
4.85 |
-0.46 |
-3.72 |
BallCalled |
4.04 |
2.62 |
5.45 |
0.2 |
Changeup |
85.55 |
1972.65 |
255.49 |
21.65 |
6.83 |
FoulBallNotFieldable |
4.15 |
2.71 |
5.51 |
8.5 |
Changeup |
86.33 |
1990.45 |
257.11 |
22.25 |
6.30 |
BallCalled |
3.94 |
2.77 |
5.68 |
8.6 |
Curveball |
77.45 |
1926.28 |
38.32 |
-3.87 |
-3.16 |
BallCalled |
4.11 |
2.73 |
5.43 |
1.3 |
Sinker |
87.85 |
2091.59 |
245.18 |
19.56 |
10.31 |
StrikeSwinging |
4.12 |
3.00 |
5.61 |
8.2 |
Changeup |
85.25 |
2079.62 |
247.62 |
20.80 |
9.85 |
StrikeCalled |
4.04 |
2.79 |
5.62 |
8.3 |
Changeup |
85.10 |
1930.50 |
248.83 |
19.60 |
8.94 |
BallCalled |
4.00 |
2.83 |
5.42 |
8.3 |
Changeup |
85.80 |
2027.72 |
245.75 |
20.55 |
10.61 |
BallCalled |
4.03 |
2.85 |
5.37 |
8.2 |
Sinker |
87.08 |
2172.38 |
242.30 |
20.03 |
11.80 |
StrikeCalled |
4.06 |
2.90 |
5.38 |
8.1 |
Changeup |
86.02 |
2063.86 |
263.89 |
21.47 |
3.56 |
StrikeCalled |
4.19 |
2.75 |
5.51 |
8.8 |
Changeup |
85.97 |
2088.66 |
248.31 |
20.74 |
9.56 |
StrikeCalled |
4.02 |
2.66 |
5.73 |
8.3 |
Changeup |
85.98 |
2072.46 |
270.77 |
21.98 |
1.07 |
BallCalled |
4.15 |
2.70 |
5.67 |
9.0 |
Slider |
78.99 |
2074.06 |
67.06 |
-2.33 |
0.77 |
BallCalled |
4.01 |
2.62 |
5.46 |
2.2 |
Changeup |
83.74 |
1972.08 |
272.77 |
22.89 |
0.30 |
InPlay |
3.96 |
2.79 |
5.61 |
9.1 |
# 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: 26
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Aidan Krupp")
Summary Pitch Table for Aidan Krupp
Changeup |
65.38% |
17 |
7 |
10 |
41.18% |
58.82% |
85.90 |
2025.79 |
4.77 |
21.92 |
260.99 |
8.7 |
4.09 |
2.84 |
5.50 |
Curveball |
19.23% |
5 |
2 |
3 |
40.00% |
60.00% |
77.17 |
1934.03 |
-2.59 |
-3.99 |
42.65 |
1.4 |
4.10 |
2.78 |
5.11 |
Sinker |
11.54% |
3 |
0 |
3 |
0.00% |
100.00% |
87.53 |
2137.73 |
8.40 |
20.96 |
251.06 |
8.4 |
4.11 |
2.86 |
5.53 |
Slider |
3.85% |
1 |
1 |
0 |
100.00% |
0.00% |
78.99 |
2074.06 |
0.77 |
-2.33 |
67.06 |
2.2 |
4.01 |
2.62 |
5.46 |
# 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: 87.85 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")
)
