# 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.14 |
2101.81 |
252.77 |
23.42 |
8.41 |
BallCalled |
5.27 |
1.78 |
5.28 |
8.4 |
Sinker |
89.26 |
2087.17 |
241.71 |
20.48 |
12.23 |
StrikeCalled |
5.32 |
1.75 |
5.09 |
8.1 |
Slider |
77.29 |
2151.97 |
121.12 |
-6.03 |
5.02 |
FoulBallNotFieldable |
5.26 |
1.76 |
4.88 |
4.0 |
Curveball |
76.65 |
2057.17 |
70.45 |
-5.14 |
-0.27 |
InPlay |
5.10 |
1.80 |
4.75 |
2.3 |
Sinker |
88.83 |
2005.49 |
253.43 |
18.15 |
6.47 |
StrikeCalled |
5.01 |
2.05 |
5.25 |
8.4 |
Changeup |
82.39 |
1564.13 |
207.71 |
6.06 |
12.80 |
HitByPitch |
5.08 |
1.81 |
5.86 |
6.9 |
Curveball |
75.12 |
1837.70 |
48.39 |
-3.61 |
-1.87 |
BallCalled |
5.10 |
2.18 |
4.74 |
1.6 |
Sinker |
88.43 |
2057.68 |
255.34 |
16.07 |
5.18 |
FoulBallNotFieldable |
5.17 |
2.06 |
5.26 |
8.5 |
Slider |
75.44 |
1004.16 |
67.41 |
-5.66 |
-0.89 |
BallCalled |
5.17 |
2.09 |
4.89 |
2.2 |
Sinker |
89.53 |
1933.81 |
239.11 |
15.69 |
10.47 |
FoulBallNotFieldable |
5.29 |
1.96 |
5.03 |
8.0 |
Sinker |
89.58 |
2045.99 |
251.10 |
17.60 |
7.14 |
BallCalled |
5.25 |
1.87 |
4.97 |
8.4 |
Sinker |
89.62 |
2033.23 |
249.04 |
15.93 |
7.20 |
StrikeSwinging |
5.30 |
1.89 |
5.10 |
8.3 |
Curveball |
75.66 |
2038.60 |
54.09 |
-9.10 |
-4.58 |
StrikeCalled |
5.12 |
1.96 |
4.91 |
1.8 |
Sinker |
89.44 |
2048.04 |
257.81 |
18.73 |
5.18 |
InPlay |
5.28 |
2.11 |
4.94 |
8.6 |
Curveball |
74.54 |
2076.38 |
124.77 |
-5.01 |
5.16 |
BallCalled |
5.23 |
2.08 |
4.65 |
4.2 |
Changeup |
88.51 |
1999.32 |
254.95 |
17.01 |
5.75 |
StrikeCalled |
5.24 |
1.85 |
5.32 |
8.5 |
Curveball |
74.81 |
1905.62 |
120.78 |
-2.52 |
3.00 |
HitByPitch |
5.27 |
2.10 |
4.78 |
4.0 |
Changeup |
87.62 |
1901.51 |
263.21 |
17.56 |
3.09 |
BallCalled |
5.11 |
1.85 |
5.40 |
8.8 |
Sinker |
87.60 |
2047.93 |
240.47 |
19.58 |
12.19 |
InPlay |
5.26 |
1.86 |
5.08 |
8.0 |
Curveball |
75.31 |
2054.34 |
50.53 |
-5.77 |
-3.38 |
StrikeCalled |
5.17 |
1.93 |
4.73 |
1.7 |
Curveball |
75.52 |
1921.24 |
45.77 |
-4.89 |
-3.47 |
BallCalled |
5.23 |
1.95 |
4.84 |
1.5 |
Curveball |
74.88 |
2108.87 |
38.14 |
-4.27 |
-4.06 |
InPlay |
5.10 |
1.89 |
4.83 |
1.3 |
Sinker |
86.65 |
2023.30 |
239.88 |
19.70 |
12.68 |
BallCalled |
5.40 |
1.66 |
5.05 |
8.0 |
Sinker |
87.61 |
2148.64 |
239.26 |
20.16 |
13.41 |
BallCalled |
5.35 |
1.89 |
5.01 |
8.0 |
Sinker |
87.11 |
2034.82 |
234.29 |
21.22 |
16.51 |
BallCalled |
5.19 |
1.74 |
5.42 |
7.8 |
Sinker |
86.89 |
2134.62 |
235.54 |
15.91 |
12.26 |
BallCalled |
5.33 |
1.83 |
5.01 |
7.9 |
Sinker |
88.89 |
2076.77 |
238.63 |
15.82 |
10.75 |
BallCalled |
5.31 |
2.08 |
5.17 |
8.0 |
Changeup |
87.32 |
1988.87 |
246.94 |
18.29 |
9.05 |
BallCalled |
5.32 |
2.07 |
4.91 |
8.2 |
Sinker |
88.10 |
2011.20 |
243.57 |
19.52 |
11.00 |
StrikeSwinging |
5.41 |
1.83 |
5.05 |
8.1 |
Slider |
76.02 |
2115.21 |
112.17 |
-3.58 |
3.09 |
BallCalled |
5.21 |
1.81 |
4.71 |
3.7 |
Changeup |
88.77 |
1991.49 |
257.36 |
19.49 |
5.56 |
BallCalled |
5.48 |
1.62 |
5.01 |
8.6 |
Curveball |
75.25 |
2024.94 |
129.20 |
-3.98 |
4.92 |
BallCalled |
5.30 |
2.11 |
4.71 |
4.3 |
Sinker |
88.76 |
2006.73 |
238.31 |
19.58 |
13.37 |
InPlay |
5.50 |
1.86 |
5.07 |
7.9 |
# 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: 33
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Jacob Lapham")
Summary Pitch Table for Jacob Lapham
Changeup |
15.15% |
5 |
3 |
2 |
60.00% |
40.00% |
86.92 |
1889.06 |
7.25 |
15.68 |
246.03 |
8.2 |
5.25 |
1.84 |
5.30 |
Curveball |
27.27% |
9 |
4 |
5 |
44.44% |
55.56% |
75.30 |
2002.76 |
-0.51 |
-4.92 |
75.79 |
2.5 |
5.18 |
2.00 |
4.77 |
Sinker |
48.48% |
16 |
7 |
9 |
43.75% |
56.25% |
88.47 |
2049.83 |
10.28 |
18.60 |
244.39 |
8.2 |
5.29 |
1.89 |
5.11 |
Slider |
9.09% |
3 |
2 |
1 |
66.67% |
33.33% |
76.25 |
1757.11 |
2.41 |
-5.09 |
100.23 |
3.3 |
5.21 |
1.89 |
4.83 |
# 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.62 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")
)
