# 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
Changeup |
87.82 |
1927.64 |
241.80 |
18.28 |
11.11 |
BallCalled |
5.15 |
1.90 |
5.18 |
8.1 |
Sinker |
89.15 |
1982.56 |
263.35 |
20.37 |
3.62 |
BallCalled |
5.33 |
1.95 |
5.34 |
8.8 |
Sinker |
88.88 |
2161.22 |
239.55 |
20.38 |
13.33 |
BallCalled |
5.35 |
1.93 |
5.25 |
8.0 |
Sinker |
88.02 |
2078.73 |
232.07 |
16.93 |
14.54 |
StrikeCalled |
5.30 |
1.88 |
5.28 |
7.7 |
Curveball |
75.47 |
2065.45 |
65.75 |
-6.11 |
-1.16 |
StrikeCalled |
5.22 |
1.75 |
4.95 |
2.2 |
Curveball |
74.99 |
2000.09 |
105.43 |
-11.95 |
5.06 |
StrikeCalled |
5.34 |
1.58 |
4.95 |
3.5 |
Curveball |
75.13 |
2070.97 |
86.61 |
-8.10 |
1.18 |
BallCalled |
5.14 |
1.95 |
5.16 |
2.9 |
Sinker |
89.20 |
2135.86 |
256.13 |
20.34 |
6.23 |
BallCalled |
5.28 |
1.86 |
5.35 |
8.5 |
Sinker |
88.00 |
1987.40 |
232.75 |
18.50 |
15.39 |
BallCalled |
5.29 |
1.93 |
5.37 |
7.8 |
Sinker |
88.07 |
2034.54 |
233.18 |
18.89 |
15.44 |
StrikeCalled |
5.42 |
1.87 |
5.25 |
7.8 |
Curveball |
75.11 |
2115.42 |
66.47 |
-4.46 |
-0.24 |
BallCalled |
5.28 |
1.76 |
5.08 |
2.2 |
Sinker |
88.72 |
2020.16 |
262.87 |
21.17 |
3.86 |
BallCalled |
5.45 |
2.13 |
5.33 |
8.8 |
Curveball |
76.27 |
1792.97 |
129.55 |
-4.16 |
5.25 |
BallCalled |
5.25 |
1.88 |
5.13 |
4.3 |
Changeup |
86.27 |
2047.98 |
251.16 |
21.62 |
8.72 |
BallCalled |
5.27 |
2.11 |
5.24 |
8.4 |
Changeup |
87.67 |
2018.22 |
254.98 |
17.34 |
5.90 |
StrikeCalled |
5.39 |
2.08 |
5.19 |
8.5 |
Changeup |
87.82 |
1854.67 |
252.46 |
17.40 |
6.68 |
FoulBallNotFieldable |
5.22 |
2.25 |
5.11 |
8.4 |
Curveball |
77.92 |
1860.45 |
66.71 |
-0.91 |
1.47 |
BallCalled |
5.24 |
1.92 |
5.36 |
2.2 |
Changeup |
87.85 |
2043.44 |
266.93 |
21.23 |
2.41 |
BallCalled |
5.40 |
2.01 |
5.51 |
8.9 |
Sinker |
88.53 |
2040.96 |
235.45 |
18.97 |
14.35 |
StrikeSwinging |
5.51 |
1.85 |
5.12 |
7.8 |
Changeup |
88.45 |
1923.63 |
260.48 |
19.24 |
4.43 |
BallCalled |
5.37 |
2.02 |
5.30 |
8.7 |
Sinker |
87.97 |
1988.64 |
235.20 |
16.40 |
12.63 |
StrikeSwinging |
5.36 |
1.98 |
5.51 |
7.8 |
Curveball |
75.87 |
2075.06 |
98.27 |
-10.00 |
3.11 |
InPlay |
5.48 |
1.98 |
4.68 |
3.3 |
Sinker |
88.56 |
2142.71 |
239.28 |
17.25 |
11.47 |
StrikeCalled |
5.28 |
1.98 |
5.43 |
8.0 |
Curveball |
75.40 |
2079.12 |
78.07 |
-8.68 |
-0.25 |
BallCalled |
5.29 |
1.86 |
4.95 |
2.6 |
Curveball |
75.29 |
2023.70 |
73.34 |
-5.61 |
-0.14 |
InPlay |
5.20 |
1.82 |
4.92 |
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: 25
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Jacob Lapham")
Summary Pitch Table for Jacob Lapham
Changeup |
24.00% |
6 |
4 |
2 |
66.67% |
33.33% |
87.65 |
1969.26 |
6.54 |
19.18 |
254.64 |
8.5 |
5.30 |
2.06 |
5.26 |
Curveball |
36.00% |
9 |
5 |
4 |
55.56% |
44.44% |
75.72 |
2009.25 |
1.59 |
-6.66 |
85.58 |
2.8 |
5.27 |
1.83 |
5.02 |
Sinker |
40.00% |
10 |
5 |
5 |
50.00% |
50.00% |
88.51 |
2057.28 |
11.09 |
18.92 |
242.98 |
8.1 |
5.36 |
1.94 |
5.32 |
# 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.2 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")
)
