knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)
library(readxl)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(knitr)
# Load the data
Sanford625 <- read_excel("C:/Users/Franco Castagliuolo/OneDrive - Bentley University/Neers 24/Pitchers/Sanford 625/Sanford 625.xlsx")
# Filter the data for the pitcher Nick Falter
Nick_Falter_data <- Sanford625 %>%
filter(Pitcher == "Falter, Nick")
# Create a detailed table for each pitch
detailed_pitch_table <- Nick_Falter_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 Nick Falter")
Detailed Pitch Table for Nick Falter
Four-Seam |
91.94 |
2489.57 |
218.93 |
12.47 |
16.60 |
StrikeCalled |
5.68 |
1.54 |
5.89 |
7.3 |
Cutter |
86.69 |
2433.08 |
186.36 |
1.30 |
12.81 |
InPlay |
5.67 |
1.69 |
5.22 |
6.2 |
Four-Seam |
92.04 |
2492.70 |
214.78 |
11.51 |
17.74 |
BallCalled |
5.76 |
1.52 |
5.87 |
7.2 |
Cutter |
86.06 |
2452.51 |
174.36 |
-1.16 |
12.92 |
FoulBallNotFieldable |
5.67 |
1.77 |
5.09 |
5.8 |
Slider |
80.93 |
2409.59 |
86.21 |
-5.53 |
1.04 |
InPlay |
5.79 |
1.76 |
5.05 |
2.9 |
Slider |
82.99 |
2365.97 |
146.95 |
-1.89 |
4.23 |
BallCalled |
5.72 |
1.53 |
5.28 |
4.9 |
Slider |
86.10 |
2356.91 |
174.18 |
-0.80 |
9.09 |
StrikeCalled |
5.69 |
1.68 |
5.11 |
5.8 |
Slider |
82.80 |
2515.21 |
122.42 |
-4.78 |
4.35 |
StrikeCalled |
5.74 |
1.64 |
4.94 |
4.1 |
Sinker |
91.77 |
2307.64 |
258.02 |
17.54 |
4.90 |
BallCalled |
5.66 |
1.56 |
5.73 |
8.6 |
Slider |
88.42 |
2546.35 |
197.82 |
1.94 |
7.25 |
InPlay |
5.69 |
1.66 |
5.13 |
6.6 |
Sinker |
90.58 |
2560.07 |
239.40 |
18.73 |
12.26 |
StrikeCalled |
5.70 |
1.66 |
5.61 |
8.0 |
Slider |
81.84 |
2391.39 |
153.30 |
-1.82 |
5.09 |
FoulBallNotFieldable |
5.76 |
1.63 |
5.05 |
5.1 |
Slider |
86.21 |
2389.22 |
203.15 |
3.72 |
9.96 |
BallCalled |
5.61 |
1.51 |
5.35 |
6.8 |
Four-Seam |
92.40 |
2494.31 |
224.67 |
12.57 |
13.84 |
StrikeSwinging |
5.66 |
1.66 |
5.55 |
7.5 |
Sinker |
91.78 |
2447.85 |
248.08 |
18.49 |
8.62 |
StrikeCalled |
5.52 |
1.60 |
5.87 |
8.3 |
Four-Seam |
92.71 |
2482.33 |
224.49 |
13.60 |
15.00 |
FoulBallNotFieldable |
5.64 |
1.61 |
5.78 |
7.5 |
Four-Seam |
92.71 |
2338.84 |
228.42 |
15.17 |
14.55 |
BallCalled |
5.62 |
1.52 |
5.64 |
7.6 |
Slider |
88.03 |
2498.82 |
172.24 |
-0.78 |
6.84 |
InPlay |
5.71 |
1.46 |
5.22 |
5.7 |
Four-Seam |
92.02 |
2529.37 |
221.22 |
11.52 |
14.18 |
StrikeCalled |
5.67 |
1.53 |
5.74 |
7.4 |
Slider |
87.85 |
2438.35 |
207.61 |
5.01 |
10.61 |
StrikeCalled |
5.59 |
1.53 |
5.27 |
6.9 |
Slider |
83.16 |
2347.72 |
120.26 |
-2.49 |
2.69 |
BallCalled |
5.79 |
1.40 |
5.23 |
4.0 |
Four-Seam |
92.21 |
2572.67 |
223.89 |
11.77 |
13.32 |
InPlay |
5.54 |
1.63 |
5.61 |
7.5 |
Slider |
86.35 |
2441.03 |
223.33 |
5.60 |
7.13 |
BallCalled |
5.63 |
1.67 |
5.38 |
7.4 |
Four-Seam |
87.45 |
2465.42 |
228.04 |
7.41 |
7.83 |
StrikeSwinging |
5.62 |
1.68 |
5.44 |
7.6 |
Four-Seam |
91.23 |
2583.84 |
230.54 |
15.13 |
13.61 |
FoulBallNotFieldable |
5.63 |
1.62 |
5.94 |
7.7 |
Sinker |
91.26 |
2348.26 |
226.76 |
12.84 |
13.17 |
BallCalled |
5.54 |
1.49 |
5.87 |
7.6 |
Cutter |
87.11 |
2387.08 |
161.25 |
-3.64 |
11.88 |
BallCalled |
5.62 |
1.51 |
5.45 |
5.4 |
Slider |
88.00 |
2417.45 |
194.05 |
2.35 |
10.41 |
BallCalled |
5.67 |
1.59 |
5.52 |
6.5 |
Sinker |
90.94 |
2351.90 |
224.43 |
12.68 |
14.03 |
BallCalled |
5.71 |
1.54 |
5.75 |
7.5 |
Slider |
84.59 |
2334.56 |
161.21 |
-2.60 |
8.87 |
StrikeCalled |
5.79 |
1.51 |
5.40 |
5.4 |
Four-Seam |
91.05 |
2375.53 |
214.64 |
10.24 |
15.99 |
StrikeSwinging |
5.67 |
1.40 |
5.97 |
7.2 |
Cutter |
86.71 |
2333.81 |
199.32 |
3.81 |
11.90 |
BallCalled |
5.72 |
1.47 |
5.54 |
6.6 |
Slider |
82.72 |
2396.07 |
119.11 |
-5.52 |
4.48 |
StrikeSwinging |
5.72 |
1.46 |
5.19 |
4.0 |
Sinker |
91.06 |
2448.18 |
224.36 |
12.74 |
14.13 |
BallCalled |
5.66 |
1.48 |
5.76 |
7.5 |
Slider |
85.39 |
2387.38 |
182.33 |
0.40 |
11.07 |
StrikeSwinging |
5.73 |
1.52 |
5.28 |
6.1 |
Slider |
80.72 |
2395.65 |
93.95 |
-5.43 |
1.89 |
InPlay |
5.75 |
1.54 |
5.09 |
3.1 |
Cutter |
85.55 |
2330.71 |
163.38 |
-3.00 |
11.31 |
StrikeCalled |
5.74 |
1.57 |
5.25 |
5.4 |
Four-Seam |
90.11 |
2475.37 |
219.15 |
12.23 |
16.22 |
FoulBallNotFieldable |
5.69 |
1.55 |
5.66 |
7.3 |
Slider |
82.03 |
2381.86 |
152.00 |
-0.93 |
2.98 |
InPlay |
5.73 |
1.41 |
5.17 |
5.1 |
Slider |
85.66 |
2344.78 |
181.28 |
0.18 |
9.26 |
FoulBallNotFieldable |
5.77 |
1.44 |
5.22 |
6.0 |
Slider |
84.42 |
2339.24 |
147.80 |
-3.77 |
7.17 |
StrikeCalled |
5.79 |
1.56 |
5.51 |
4.9 |
Four-Seam |
91.34 |
2586.57 |
210.48 |
8.96 |
16.27 |
StrikeSwinging |
5.74 |
1.46 |
5.81 |
7.0 |
Sinker |
90.44 |
2369.41 |
236.52 |
16.58 |
12.13 |
FoulBallNotFieldable |
5.68 |
1.54 |
5.71 |
7.9 |
Four-Seam |
87.35 |
2411.98 |
213.19 |
6.57 |
11.11 |
FoulBallNotFieldable |
5.66 |
1.58 |
5.59 |
7.1 |
Slider |
84.62 |
2272.40 |
205.50 |
1.28 |
4.03 |
InPlay |
5.67 |
1.50 |
5.41 |
6.8 |
Slider |
85.79 |
2339.32 |
204.14 |
3.69 |
9.25 |
InPlay |
5.60 |
1.60 |
5.49 |
6.8 |
Sinker |
91.25 |
2259.67 |
239.00 |
15.79 |
10.51 |
FoulBallNotFieldable |
5.66 |
1.46 |
6.17 |
8.0 |
Slider |
86.50 |
2395.91 |
167.59 |
-2.09 |
10.76 |
BallCalled |
5.84 |
1.51 |
5.35 |
5.6 |
Four-Seam |
91.65 |
2534.18 |
223.05 |
13.20 |
15.31 |
InPlay |
5.71 |
1.48 |
6.01 |
7.4 |
Sinker |
90.74 |
2444.98 |
238.39 |
16.49 |
11.33 |
StrikeCalled |
5.69 |
1.45 |
5.92 |
7.9 |
Sinker |
92.15 |
2489.25 |
236.95 |
16.00 |
11.60 |
BallCalled |
5.71 |
1.41 |
5.88 |
7.9 |
Four-Seam |
91.31 |
2464.13 |
220.02 |
12.36 |
15.97 |
StrikeCalled |
5.68 |
1.48 |
5.99 |
7.3 |
Slider |
83.98 |
2352.78 |
188.97 |
0.45 |
4.28 |
BallCalled |
5.68 |
1.39 |
5.60 |
6.3 |
Four-Seam |
91.41 |
2511.70 |
212.83 |
10.15 |
16.95 |
BallCalled |
5.71 |
1.46 |
5.86 |
7.1 |
Cutter |
87.27 |
2459.43 |
205.33 |
4.74 |
11.30 |
StrikeSwinging |
5.74 |
1.56 |
5.32 |
6.8 |
Slider |
84.75 |
2368.91 |
202.83 |
4.24 |
11.26 |
FoulBallNotFieldable |
5.80 |
1.60 |
5.32 |
6.8 |
Slider |
82.14 |
2321.82 |
125.97 |
-2.35 |
3.26 |
StrikeCalled |
5.71 |
1.64 |
5.32 |
4.2 |
Slider |
81.44 |
2431.54 |
103.96 |
-2.45 |
2.14 |
StrikeSwinging |
5.75 |
1.46 |
5.26 |
3.5 |
Sinker |
90.43 |
2436.27 |
230.59 |
14.55 |
13.22 |
InPlay |
5.67 |
1.52 |
5.83 |
7.7 |
Sinker |
89.99 |
2411.39 |
242.51 |
17.04 |
10.16 |
FoulBallNotFieldable |
5.72 |
1.49 |
5.46 |
8.1 |
Sinker |
90.53 |
2403.25 |
227.20 |
14.00 |
14.13 |
BallCalled |
5.80 |
1.64 |
5.68 |
7.6 |
Slider |
85.23 |
2394.14 |
183.14 |
0.45 |
9.34 |
BallCalled |
5.75 |
1.54 |
5.30 |
6.1 |
Sinker |
91.19 |
2528.90 |
230.89 |
15.47 |
13.69 |
FoulBallNotFieldable |
5.73 |
1.43 |
5.83 |
7.7 |
Sinker |
91.06 |
2294.25 |
239.60 |
15.12 |
9.99 |
FoulBallNotFieldable |
5.70 |
1.53 |
5.43 |
8.0 |
Sinker |
90.04 |
2146.60 |
233.47 |
15.44 |
12.52 |
BallCalled |
5.77 |
1.33 |
5.70 |
7.8 |
Slider |
86.55 |
2366.66 |
221.59 |
2.74 |
4.21 |
StrikeCalled |
5.71 |
1.53 |
5.10 |
7.4 |
Four-Seam |
91.44 |
2436.46 |
219.11 |
11.95 |
15.74 |
FoulBallNotFieldable |
5.75 |
1.42 |
5.75 |
7.3 |
Slider |
86.77 |
2401.26 |
187.62 |
1.12 |
9.59 |
BallCalled |
5.77 |
1.45 |
5.42 |
6.3 |
Four-Seam |
92.51 |
2495.09 |
202.04 |
7.43 |
19.54 |
StrikeSwinging |
5.81 |
1.58 |
5.72 |
6.7 |
Slider |
83.69 |
2280.08 |
164.90 |
-0.86 |
4.48 |
BallCalled |
5.76 |
1.44 |
5.29 |
5.5 |
Slider |
86.42 |
2385.70 |
187.03 |
0.98 |
9.09 |
BallCalled |
5.76 |
1.46 |
5.42 |
6.2 |
Four-Seam |
92.93 |
2503.20 |
207.91 |
9.00 |
18.13 |
BallCalled |
5.75 |
1.48 |
5.82 |
6.9 |
Slider |
86.31 |
2379.05 |
198.97 |
2.53 |
8.59 |
StrikeCalled |
5.76 |
1.50 |
5.47 |
6.6 |
Four-Seam |
91.14 |
2442.72 |
208.91 |
9.74 |
18.86 |
BallCalled |
5.70 |
1.38 |
6.01 |
7.0 |
Cutter |
87.10 |
2461.80 |
192.87 |
3.05 |
14.47 |
FoulBallNotFieldable |
5.75 |
1.51 |
5.48 |
6.4 |
Slider |
83.05 |
2329.27 |
131.25 |
-3.05 |
4.09 |
StrikeSwinging |
5.78 |
1.43 |
5.33 |
4.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 == "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: 76
# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Nick Falter")
Summary Pitch Table for Nick Falter
Cutter |
9.21% |
7 |
2 |
5 |
28.57% |
71.43% |
86.64 |
2408.35 |
12.37 |
0.73 |
183.27 |
6.1 |
5.70 |
1.58 |
5.34 |
Four-Seam |
26.32% |
20 |
5 |
15 |
25.00% |
75.00% |
91.35 |
2484.30 |
15.34 |
11.15 |
218.32 |
7.3 |
5.68 |
1.53 |
5.78 |
Sinker |
21.05% |
16 |
7 |
9 |
43.75% |
56.25% |
90.95 |
2390.49 |
11.65 |
15.59 |
236.01 |
7.9 |
5.68 |
1.51 |
5.76 |
Slider |
43.42% |
33 |
11 |
22 |
33.33% |
66.67% |
84.71 |
2385.35 |
6.63 |
-0.32 |
167.05 |
5.6 |
5.73 |
1.53 |
5.29 |
# 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("Nick Falter maximum FB velocity: ", max_fb_velocity, "mph\n")
## Nick Falter maximum FB velocity: 92.93 mph
# Prepare data for plotting pitch locations
pitch_location_data <- Nick_Falter_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) + # Increase point size
geom_rect(aes(xmin = -0.5, xmax = 0.5, ymin = 1.75, ymax = 3.25), fill = NA, color = "red", linetype = "solid", size = 1) + # Red box
geom_rect(aes(xmin = -0.75, xmax = 0.75, ymin = 1.5, ymax = 3.5), fill = NA, color = "black", linetype = "solid", size = 1) + # Black box
geom_rect(aes(xmin = -1.25, xmax = 1.25, ymin = 1.25, ymax = 3.75), fill = NA, color = "gray", linetype = "solid", size = 1) + # Gray box
scale_x_continuous(limits = c(-2, 2)) +
scale_y_continuous(limits = c(0, 5)) +
coord_fixed(ratio = 1) + # Adjust ratio to shrink vertical distance
labs(title = "Pitch Locations for Nick Falter",
x = "Horizontal Location (feet)",
y = "Vertical Location (feet)",
color = "Swing/Take",
shape = "Chase") +
facet_wrap(~ AutoPitchType) + # Create individual graphs for each 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")
)

# 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
labs(title = "Pitch Movement for Nick Falter",
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")
)
