# 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.24 |
2139.15 |
243.52 |
17.90 |
10.16 |
BallCalled |
5.42 |
2.04 |
5.11 |
8.1 |
Sinker |
89.30 |
2081.24 |
242.76 |
18.25 |
10.53 |
InPlay |
5.44 |
1.99 |
5.09 |
8.1 |
Curveball |
74.42 |
2073.06 |
88.96 |
-8.15 |
1.63 |
BallCalled |
5.59 |
1.54 |
4.77 |
3.0 |
Sinker |
89.36 |
2140.41 |
256.48 |
20.17 |
6.01 |
InPlay |
5.52 |
1.94 |
4.98 |
8.5 |
Curveball |
74.77 |
1916.65 |
53.29 |
-5.42 |
-2.06 |
BallCalled |
5.30 |
1.81 |
4.78 |
1.8 |
Sinker |
89.30 |
2276.88 |
232.83 |
17.65 |
14.53 |
FoulBallNotFieldable |
5.50 |
1.87 |
4.89 |
7.8 |
Curveball |
74.86 |
1907.59 |
45.33 |
-4.21 |
-2.25 |
BallCalled |
5.26 |
1.89 |
4.89 |
1.5 |
Sinker |
88.62 |
2107.28 |
237.23 |
17.88 |
12.68 |
BallCalled |
5.71 |
1.77 |
5.14 |
7.9 |
Sinker |
89.89 |
2216.21 |
233.53 |
18.28 |
14.80 |
BallCalled |
5.55 |
2.02 |
4.69 |
7.8 |
Sinker |
88.27 |
2209.12 |
240.44 |
22.06 |
13.76 |
BallCalled |
5.47 |
1.96 |
4.94 |
8.0 |
Sinker |
88.13 |
2121.89 |
250.46 |
19.95 |
8.24 |
FoulBallNotFieldable |
5.49 |
1.88 |
5.05 |
8.3 |
Sinker |
88.73 |
2071.70 |
250.75 |
16.62 |
6.92 |
BallCalled |
5.38 |
1.99 |
4.94 |
8.4 |
Changeup |
87.40 |
2001.05 |
261.72 |
19.14 |
3.95 |
BallCalled |
5.39 |
2.08 |
4.89 |
8.7 |
Sinker |
87.99 |
2149.99 |
226.58 |
15.18 |
15.60 |
BallCalled |
5.46 |
1.92 |
4.83 |
7.6 |
Sinker |
87.83 |
2107.99 |
241.09 |
18.32 |
11.43 |
BallCalled |
5.62 |
2.10 |
4.82 |
8.0 |
Sinker |
88.04 |
2085.38 |
243.55 |
16.45 |
9.36 |
FoulBallNotFieldable |
5.46 |
2.10 |
5.03 |
8.1 |
Sinker |
88.99 |
2137.53 |
250.18 |
17.88 |
7.58 |
InPlay |
5.46 |
1.99 |
5.03 |
8.3 |
Sinker |
88.43 |
2096.51 |
225.56 |
14.83 |
15.82 |
BallCalled |
5.67 |
1.89 |
5.13 |
7.5 |
Sinker |
87.36 |
2097.45 |
227.63 |
17.24 |
16.99 |
StrikeCalled |
5.67 |
1.85 |
4.99 |
7.6 |
Slider |
74.69 |
2186.90 |
101.31 |
-3.66 |
2.28 |
BallCalled |
5.47 |
1.80 |
4.75 |
3.4 |
Sinker |
88.23 |
2074.77 |
247.89 |
19.25 |
8.95 |
BallCalled |
5.69 |
1.71 |
5.10 |
8.3 |
Sinker |
88.16 |
2091.00 |
230.83 |
18.10 |
16.01 |
StrikeCalled |
5.49 |
1.75 |
4.92 |
7.7 |
Sinker |
88.89 |
2190.34 |
234.14 |
18.54 |
14.66 |
StrikeCalled |
5.61 |
1.44 |
4.96 |
7.8 |
Curveball |
75.70 |
2025.98 |
76.74 |
-6.06 |
0.39 |
BallCalled |
5.42 |
2.15 |
4.81 |
2.6 |
Sinker |
88.48 |
2087.72 |
251.64 |
19.49 |
7.61 |
BallCalled |
5.78 |
1.74 |
4.95 |
8.4 |
Sinker |
87.80 |
2063.41 |
237.03 |
18.06 |
12.99 |
HitByPitch |
5.58 |
1.93 |
4.95 |
7.9 |
Sinker |
88.36 |
2055.21 |
238.86 |
17.41 |
11.68 |
BallCalled |
5.42 |
1.95 |
5.00 |
8.0 |
Sinker |
88.94 |
2026.09 |
260.00 |
21.77 |
5.03 |
FoulBallNotFieldable |
5.58 |
1.90 |
4.96 |
8.7 |
Sinker |
88.80 |
2057.54 |
253.43 |
18.55 |
6.71 |
BallCalled |
5.46 |
1.97 |
5.02 |
8.4 |
Sinker |
87.51 |
2050.08 |
257.20 |
22.79 |
6.51 |
StrikeSwinging |
5.44 |
1.84 |
4.84 |
8.6 |
Curveball |
75.71 |
1981.43 |
57.42 |
-9.90 |
-4.43 |
FoulBallNotFieldable |
5.38 |
1.96 |
4.76 |
1.9 |
Sinker |
89.07 |
2224.61 |
226.03 |
16.09 |
16.70 |
BallCalled |
5.57 |
1.97 |
4.91 |
7.5 |
Sinker |
89.82 |
2168.53 |
226.39 |
15.53 |
15.96 |
InPlay |
5.54 |
1.72 |
4.74 |
7.5 |
Sinker |
89.14 |
2077.12 |
246.86 |
17.20 |
8.51 |
BallCalled |
5.43 |
1.96 |
4.97 |
8.2 |
Sinker |
89.37 |
2200.45 |
233.54 |
17.31 |
14.01 |
StrikeCalled |
5.58 |
2.01 |
4.85 |
7.8 |
Sinker |
88.39 |
2122.00 |
229.65 |
16.03 |
14.81 |
BallCalled |
5.47 |
1.93 |
4.96 |
7.7 |
Curveball |
73.25 |
2013.45 |
62.58 |
-4.12 |
-0.45 |
BallCalled |
5.39 |
1.88 |
4.68 |
2.1 |
Sinker |
87.37 |
2119.55 |
237.08 |
18.56 |
13.27 |
FoulBallNotFieldable |
5.63 |
2.06 |
4.96 |
7.9 |
Sinker |
88.12 |
2046.55 |
252.96 |
18.77 |
6.93 |
InPlay |
5.52 |
1.87 |
5.05 |
8.4 |
Sinker |
89.71 |
2255.06 |
227.82 |
14.37 |
14.43 |
BallCalled |
5.73 |
1.58 |
5.02 |
7.6 |
Sinker |
88.76 |
2233.47 |
227.10 |
15.82 |
16.12 |
BallCalled |
5.63 |
1.97 |
5.04 |
7.6 |
Sinker |
87.63 |
2094.82 |
241.69 |
19.45 |
11.83 |
BallCalled |
5.64 |
1.90 |
5.24 |
8.1 |
Sinker |
87.04 |
2132.92 |
237.80 |
18.05 |
12.79 |
BallCalled |
5.62 |
1.99 |
4.85 |
7.9 |
Curveball |
75.45 |
2070.91 |
40.09 |
-5.65 |
-4.79 |
StrikeSwinging |
5.31 |
1.78 |
4.56 |
1.3 |
Sinker |
88.19 |
2104.47 |
247.35 |
19.89 |
9.57 |
StrikeCalled |
5.71 |
1.89 |
5.18 |
8.2 |
Curveball |
75.61 |
2026.65 |
72.23 |
-6.65 |
-0.38 |
InPlay |
5.38 |
2.03 |
4.85 |
2.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: 46
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Jacob Lapham")
Summary Pitch Table for Jacob Lapham
Changeup |
2.17% |
1 |
1 |
0 |
100.00% |
0.00% |
87.40 |
2001.05 |
3.95 |
19.14 |
261.72 |
8.7 |
5.39 |
2.08 |
4.89 |
Curveball |
17.39% |
8 |
5 |
3 |
62.50% |
37.50% |
74.97 |
2001.96 |
-1.54 |
-6.27 |
62.08 |
2.1 |
5.38 |
1.88 |
4.76 |
Sinker |
78.26% |
36 |
19 |
17 |
52.78% |
47.22% |
88.53 |
2125.40 |
11.65 |
18.05 |
240.22 |
8.0 |
5.55 |
1.90 |
4.98 |
Slider |
2.17% |
1 |
1 |
0 |
100.00% |
0.00% |
74.69 |
2186.90 |
2.28 |
-3.66 |
101.31 |
3.4 |
5.47 |
1.80 |
4.75 |
# 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("Jacob Lapham maximum FB velocity: ", max_fb_velocity, "mph\n")
## Jacob Lapham maximum FB velocity: 89.89 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 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"),
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")
)
