# Filter the data for the pitcher Jacob Lapham
Brian_Foley_data <- data %>%
filter(Pitcher == "Lapham, Jacob")
# 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 Jacob Lapham")
Detailed Pitch Table for Jacob Lapham
Sinker |
89.18 |
1988.94 |
256.05 |
19.88 |
6.08 |
BallCalled |
5.12 |
2.06 |
5.25 |
8.5 |
Sinker |
88.78 |
2051.46 |
242.09 |
18.45 |
10.96 |
StrikeCalled |
5.09 |
2.03 |
5.13 |
8.1 |
Curveball |
76.19 |
2019.07 |
94.24 |
-10.99 |
2.37 |
FoulBallNotFieldable |
5.09 |
2.23 |
4.82 |
3.1 |
Curveball |
76.49 |
2155.21 |
49.09 |
-5.18 |
-2.93 |
FoulBallNotFieldable |
5.07 |
2.38 |
4.81 |
1.6 |
Sinker |
90.94 |
2171.91 |
229.27 |
16.08 |
14.99 |
BallCalled |
5.46 |
2.25 |
4.97 |
7.6 |
Sinker |
90.16 |
2064.87 |
268.84 |
18.61 |
1.47 |
BallCalled |
5.12 |
2.25 |
4.99 |
9.0 |
Sinker |
90.17 |
2022.67 |
267.59 |
19.55 |
1.91 |
InPlay |
5.03 |
2.20 |
4.95 |
8.9 |
Sinker |
89.06 |
2149.72 |
261.17 |
19.43 |
4.17 |
BallCalled |
5.14 |
2.17 |
5.45 |
8.7 |
Sinker |
89.04 |
2110.24 |
232.10 |
16.54 |
14.14 |
InPlay |
5.38 |
1.75 |
4.85 |
7.7 |
Sinker |
91.34 |
2201.70 |
250.33 |
17.36 |
7.38 |
StrikeSwinging |
5.37 |
1.80 |
4.84 |
8.3 |
Changeup |
81.71 |
1711.96 |
216.03 |
10.05 |
15.26 |
BallCalled |
5.06 |
2.05 |
5.75 |
7.2 |
Sinker |
90.04 |
2084.38 |
260.56 |
19.65 |
4.49 |
FoulBallNotFieldable |
5.16 |
2.00 |
4.92 |
8.7 |
Slider |
77.41 |
2211.98 |
100.40 |
-4.85 |
2.73 |
FoulBallNotFieldable |
5.14 |
1.95 |
4.90 |
3.3 |
Changeup |
82.76 |
1535.45 |
239.16 |
13.26 |
9.27 |
StrikeSwinging |
5.04 |
1.82 |
5.90 |
8.0 |
Sinker |
89.99 |
2182.81 |
250.63 |
18.04 |
7.50 |
BallCalled |
5.21 |
2.03 |
4.99 |
8.4 |
Sinker |
90.27 |
2135.43 |
258.98 |
19.76 |
4.99 |
InPlay |
5.21 |
1.79 |
5.11 |
8.6 |
Sinker |
90.74 |
2163.73 |
233.93 |
17.77 |
14.11 |
FoulBallNotFieldable |
5.30 |
2.06 |
4.67 |
7.8 |
Slider |
78.79 |
2182.20 |
73.17 |
-5.88 |
-0.05 |
StrikeSwinging |
5.05 |
1.97 |
5.09 |
2.4 |
Curveball |
76.59 |
2147.91 |
51.26 |
-8.60 |
-5.17 |
BallCalled |
5.14 |
1.97 |
4.76 |
1.7 |
Curveball |
77.24 |
2011.95 |
57.31 |
-5.90 |
-2.07 |
InPlay |
5.09 |
2.03 |
4.93 |
1.9 |
Sinker |
88.83 |
2072.69 |
252.62 |
17.77 |
6.76 |
BallCalled |
5.28 |
2.00 |
5.08 |
8.4 |
Sinker |
88.98 |
2133.90 |
230.90 |
17.16 |
15.21 |
FoulBallNotFieldable |
5.39 |
1.83 |
4.80 |
7.7 |
Changeup |
81.39 |
1653.98 |
220.20 |
11.83 |
15.40 |
InPlay |
5.10 |
2.04 |
5.57 |
7.3 |
Sinker |
89.63 |
2133.68 |
232.30 |
16.65 |
14.20 |
StrikeCalled |
5.30 |
1.92 |
4.77 |
7.7 |
Curveball |
75.96 |
1574.23 |
104.58 |
-4.45 |
2.97 |
BallCalled |
5.07 |
1.84 |
5.06 |
3.5 |
Sinker |
89.30 |
2220.79 |
230.07 |
16.49 |
15.13 |
FoulBallNotFieldable |
5.45 |
1.84 |
4.94 |
7.7 |
Curveball |
76.01 |
1987.98 |
60.80 |
-3.20 |
-0.15 |
BallCalled |
5.19 |
1.97 |
4.89 |
2.0 |
Sinker |
90.76 |
2308.47 |
234.35 |
17.11 |
13.52 |
BallCalled |
5.38 |
1.73 |
4.89 |
7.8 |
Sinker |
89.54 |
2144.99 |
228.85 |
15.91 |
15.17 |
InPlay |
5.34 |
1.90 |
4.87 |
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")
## Total number of pitches thrown: 29
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Jacob Lapham")
Summary Pitch Table for Jacob Lapham
Changeup |
10.34% |
3 |
1 |
2 |
33.33% |
66.67% |
81.95 |
1633.80 |
13.31 |
11.71 |
225.13 |
7.5 |
5.07 |
1.97 |
5.74 |
Curveball |
20.69% |
6 |
3 |
3 |
50.00% |
50.00% |
76.41 |
1982.72 |
-0.83 |
-6.39 |
69.55 |
2.3 |
5.11 |
2.07 |
4.88 |
Sinker |
62.07% |
18 |
7 |
11 |
38.89% |
61.11% |
89.82 |
2130.13 |
9.57 |
17.90 |
245.59 |
8.2 |
5.26 |
1.98 |
4.97 |
Slider |
6.90% |
2 |
0 |
2 |
0.00% |
100.00% |
78.10 |
2197.09 |
1.34 |
-5.36 |
86.78 |
2.8 |
5.10 |
1.96 |
5.00 |
# 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("Jacob Lapham maximum FB velocity: ", max_fb_velocity, "mph\n")
## Jacob Lapham maximum FB velocity: 91.34 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 Jacob Lapham",
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 for", unique(detailed_pitch_table$AutoPitchType)),
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")
)
