# 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
Curveball |
74.41 |
2123.89 |
66.79 |
-8.49 |
-2.04 |
StrikeCalled |
4.11 |
3.07 |
5.38 |
2.2 |
Curveball |
74.09 |
2059.75 |
90.80 |
-8.03 |
1.74 |
FoulBallNotFieldable |
4.14 |
2.99 |
5.20 |
3.0 |
Curveball |
74.58 |
2049.31 |
69.70 |
-9.22 |
-1.67 |
StrikeCalled |
4.19 |
3.08 |
5.36 |
2.3 |
Curveball |
73.22 |
1995.17 |
81.29 |
-9.89 |
0.19 |
BallCalled |
4.16 |
3.05 |
5.16 |
2.7 |
Changeup |
84.89 |
2042.17 |
258.03 |
21.86 |
6.06 |
BallCalled |
4.05 |
3.10 |
5.56 |
8.6 |
Curveball |
76.01 |
2176.07 |
55.86 |
-11.07 |
-5.91 |
FoulBallNotFieldable |
4.11 |
3.04 |
5.39 |
1.9 |
Changeup |
86.07 |
2061.54 |
262.26 |
22.52 |
4.38 |
FoulBallNotFieldable |
4.06 |
3.28 |
5.53 |
8.7 |
Curveball |
73.39 |
2090.96 |
64.18 |
-8.49 |
-2.28 |
StrikeSwinging |
3.93 |
2.91 |
5.53 |
2.1 |
Curveball |
72.88 |
1998.27 |
74.29 |
-8.27 |
-0.51 |
BallCalled |
4.19 |
2.88 |
5.38 |
2.5 |
Changeup |
83.65 |
1927.83 |
245.04 |
20.79 |
11.06 |
InPlay |
4.36 |
3.18 |
5.31 |
8.2 |
Changeup |
84.59 |
2016.29 |
251.87 |
21.88 |
8.55 |
StrikeCalled |
4.24 |
2.89 |
5.39 |
8.4 |
Changeup |
85.00 |
2122.17 |
244.21 |
22.00 |
12.01 |
BallCalled |
4.27 |
2.96 |
5.43 |
8.1 |
Curveball |
73.59 |
2151.24 |
75.59 |
-7.61 |
-0.37 |
InPlay |
4.10 |
2.99 |
5.41 |
2.5 |
Curveball |
74.64 |
1995.58 |
39.35 |
-4.41 |
-3.75 |
BallCalled |
4.34 |
2.78 |
5.28 |
1.3 |
Changeup |
84.08 |
2063.70 |
252.45 |
23.15 |
8.76 |
StrikeCalled |
4.22 |
3.06 |
5.37 |
8.4 |
Curveball |
74.53 |
2205.04 |
78.74 |
-13.48 |
-1.04 |
StrikeSwinging |
4.22 |
2.99 |
5.31 |
2.6 |
Curveball |
74.81 |
2184.22 |
70.79 |
-6.55 |
-0.71 |
BallCalled |
4.16 |
3.02 |
5.44 |
2.4 |
Curveball |
74.90 |
1923.02 |
68.40 |
-9.29 |
-2.03 |
BallCalled |
4.17 |
3.13 |
5.33 |
2.3 |
Changeup |
87.31 |
2118.13 |
252.59 |
21.60 |
8.06 |
HitByPitch |
4.22 |
3.17 |
5.56 |
8.4 |
Curveball |
74.55 |
2125.91 |
90.67 |
-9.89 |
1.68 |
BallCalled |
4.16 |
3.08 |
5.53 |
3.0 |
Changeup |
84.08 |
1930.89 |
245.12 |
18.67 |
9.97 |
BallCalled |
4.14 |
3.15 |
5.62 |
8.2 |
Curveball |
77.30 |
2210.50 |
84.64 |
-11.35 |
0.43 |
BallCalled |
4.03 |
3.22 |
5.75 |
2.8 |
Changeup |
86.63 |
2027.48 |
249.55 |
20.02 |
8.69 |
StrikeCalled |
4.13 |
3.13 |
5.65 |
8.3 |
Changeup |
85.35 |
2012.74 |
251.00 |
19.89 |
8.10 |
BallCalled |
4.15 |
3.18 |
5.52 |
8.4 |
Curveball |
75.31 |
2133.86 |
72.32 |
-9.77 |
-1.58 |
BallCalled |
4.05 |
3.19 |
5.57 |
2.4 |
Changeup |
86.59 |
2068.12 |
251.84 |
22.46 |
8.56 |
StrikeSwinging |
4.03 |
3.17 |
5.73 |
8.4 |
Changeup |
85.67 |
2004.84 |
254.57 |
21.68 |
7.24 |
BallCalled |
3.94 |
3.06 |
5.78 |
8.5 |
Changeup |
86.95 |
2121.79 |
248.62 |
21.63 |
9.69 |
BallCalled |
3.99 |
3.33 |
5.69 |
8.3 |
Changeup |
84.99 |
1999.67 |
251.79 |
21.58 |
8.35 |
HitByPitch |
4.10 |
3.25 |
5.48 |
8.4 |
# 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: 29
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Aidan Krupp")
Summary Pitch Table for Aidan Krupp
Changeup |
48.28% |
14 |
6 |
8 |
42.86% |
57.14% |
85.42 |
2036.95 |
8.53 |
21.41 |
251.35 |
8.4 |
4.14 |
3.14 |
5.54 |
Curveball |
51.72% |
15 |
8 |
7 |
53.33% |
46.67% |
74.55 |
2094.85 |
-1.19 |
-9.05 |
72.23 |
2.4 |
4.14 |
3.03 |
5.40 |
# 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: -Inf 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")
)
