# Filter the data for the pitcher Alekson
Alekson_data <- Adams619 %>%
filter(Pitcher == 'Alekson, Ben')
# Create a detailed table for each pitch
detailed_pitch_table <- Alekson_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 Alekson')
Detailed Pitch Table for Alekson
Four-Seam |
89.57 |
2091.02 |
221.54 |
14.41 |
17.39 |
FoulBallNotFieldable |
5.92 |
0.95 |
5.00 |
7.4 |
Changeup |
81.54 |
1545.73 |
272.85 |
17.14 |
0.50 |
BallCalled |
5.85 |
1.21 |
4.81 |
9.1 |
Sinker |
90.14 |
2075.87 |
224.64 |
14.61 |
15.98 |
BallCalled |
5.88 |
1.02 |
4.77 |
7.5 |
Slider |
79.70 |
1940.53 |
111.49 |
-3.13 |
2.70 |
InPlay |
5.97 |
1.03 |
4.91 |
3.7 |
Changeup |
80.74 |
1876.11 |
247.00 |
17.77 |
8.91 |
InPlay |
5.76 |
1.22 |
5.00 |
8.2 |
Four-Seam |
90.16 |
2147.04 |
220.74 |
14.71 |
18.22 |
StrikeSwinging |
5.87 |
1.05 |
5.03 |
7.4 |
Changeup |
81.69 |
1533.47 |
247.71 |
14.64 |
7.33 |
InPlay |
5.84 |
1.24 |
4.97 |
8.3 |
Sinker |
88.71 |
2143.52 |
225.51 |
14.78 |
15.68 |
FoulBallNotFieldable |
5.80 |
1.02 |
5.33 |
7.5 |
Changeup |
81.59 |
1791.76 |
242.58 |
15.31 |
9.34 |
FoulBallNotFieldable |
5.81 |
1.19 |
5.07 |
8.1 |
Changeup |
81.73 |
1759.78 |
252.56 |
13.40 |
5.54 |
BallCalled |
5.87 |
1.26 |
4.89 |
8.4 |
Four-Seam |
89.71 |
2134.23 |
220.85 |
14.47 |
17.95 |
FoulBallNotFieldable |
5.92 |
1.02 |
5.06 |
7.4 |
Changeup |
80.68 |
1448.66 |
276.32 |
13.09 |
-0.14 |
BallCalled |
5.91 |
1.26 |
5.04 |
9.2 |
Sinker |
90.20 |
2045.67 |
227.06 |
14.87 |
14.90 |
InPlay |
5.88 |
1.22 |
4.96 |
7.6 |
Four-Seam |
90.30 |
2052.78 |
220.63 |
13.76 |
17.10 |
StrikeCalled |
5.96 |
0.97 |
4.95 |
7.4 |
Slider |
83.46 |
1905.87 |
162.39 |
-2.26 |
8.28 |
InPlay |
5.91 |
0.94 |
5.14 |
5.4 |
Changeup |
82.17 |
1711.68 |
237.61 |
13.45 |
9.83 |
InPlay |
5.83 |
1.36 |
4.82 |
7.9 |
Four-Seam |
88.95 |
2099.88 |
215.47 |
12.42 |
18.55 |
FoulBallNotFieldable |
5.91 |
0.98 |
4.97 |
7.2 |
Sinker |
89.06 |
2156.44 |
226.05 |
14.73 |
15.46 |
InPlay |
5.86 |
1.20 |
5.01 |
7.5 |
Sinker |
88.38 |
2031.33 |
225.44 |
14.97 |
15.95 |
StrikeCalled |
5.89 |
0.83 |
5.10 |
7.5 |
Slider |
82.05 |
1862.25 |
157.71 |
-2.06 |
6.28 |
FoulBallNotFieldable |
5.92 |
1.05 |
5.04 |
5.3 |
Slider |
82.22 |
1933.33 |
215.82 |
1.93 |
4.00 |
StrikeCalled |
5.93 |
1.17 |
5.05 |
7.2 |
Sinker |
89.45 |
2099.48 |
220.83 |
15.32 |
18.91 |
FoulBallNotFieldable |
5.95 |
1.00 |
5.09 |
7.4 |
Slider |
80.52 |
1924.45 |
75.57 |
-0.82 |
1.35 |
BallCalled |
5.85 |
1.02 |
4.96 |
2.5 |
Sinker |
90.69 |
2190.40 |
233.07 |
17.39 |
14.29 |
BallCalled |
5.85 |
1.07 |
5.07 |
7.8 |
Sinker |
89.95 |
2218.37 |
227.50 |
12.32 |
12.58 |
InPlay |
5.95 |
0.89 |
4.90 |
7.6 |
Slider |
82.18 |
1964.39 |
154.89 |
-2.23 |
6.16 |
BallCalled |
5.92 |
1.09 |
5.01 |
5.2 |
Changeup |
81.82 |
1674.12 |
249.00 |
16.69 |
7.79 |
InPlay |
5.89 |
1.11 |
5.04 |
8.3 |
Sinker |
87.82 |
2033.08 |
223.96 |
15.06 |
16.92 |
InPlay |
5.94 |
0.99 |
5.25 |
7.5 |
Changeup |
79.83 |
1447.85 |
239.58 |
12.43 |
8.74 |
InPlay |
5.89 |
1.15 |
4.88 |
8.0 |
Four-Seam |
89.06 |
2073.71 |
217.02 |
13.48 |
19.12 |
StrikeSwinging |
5.89 |
1.05 |
5.09 |
7.2 |
Changeup |
80.58 |
1806.46 |
240.51 |
14.83 |
9.81 |
InPlay |
5.84 |
1.14 |
5.07 |
8.0 |
Four-Seam |
87.77 |
2070.42 |
212.75 |
11.79 |
19.58 |
StrikeCalled |
5.96 |
0.85 |
4.88 |
7.1 |
Changeup |
79.52 |
1466.92 |
266.06 |
18.06 |
2.74 |
BallCalled |
5.94 |
1.05 |
5.09 |
8.9 |
Sinker |
89.00 |
2152.97 |
222.00 |
15.85 |
18.82 |
InPlay |
5.90 |
1.05 |
5.14 |
7.4 |
Four-Seam |
89.39 |
2168.74 |
215.48 |
13.30 |
19.92 |
BallCalled |
5.81 |
0.96 |
5.08 |
7.2 |
Changeup |
79.69 |
1518.77 |
263.09 |
18.60 |
3.77 |
BallCalled |
5.82 |
1.10 |
4.95 |
8.8 |
Sinker |
89.47 |
2037.40 |
220.57 |
14.73 |
18.40 |
BallCalled |
5.91 |
1.00 |
5.08 |
7.4 |
Sinker |
89.58 |
2079.30 |
218.13 |
14.10 |
19.14 |
StrikeCalled |
5.82 |
0.92 |
5.02 |
7.3 |
Four-Seam |
91.08 |
2155.93 |
217.53 |
12.12 |
16.98 |
InPlay |
5.78 |
1.04 |
4.91 |
7.3 |
Sinker |
88.35 |
2048.36 |
231.85 |
15.15 |
13.05 |
StrikeCalled |
5.96 |
0.86 |
5.09 |
7.7 |
Changeup |
82.16 |
1433.25 |
249.42 |
11.87 |
5.67 |
FoulBallNotFieldable |
5.86 |
1.02 |
5.14 |
8.3 |
Changeup |
82.70 |
1616.96 |
245.78 |
13.50 |
7.39 |
InPlay |
5.77 |
1.02 |
5.01 |
8.2 |
Four-Seam |
87.97 |
2006.10 |
216.86 |
12.41 |
17.80 |
StrikeCalled |
5.96 |
0.87 |
5.17 |
7.2 |
NA |
89.02 |
2064.19 |
NA |
NA |
NA |
BallCalled |
6.09 |
1.03 |
5.33 |
NA |
Changeup |
80.76 |
1457.46 |
260.67 |
15.02 |
3.87 |
StrikeCalled |
5.94 |
0.98 |
5.07 |
8.7 |
Four-Seam |
88.59 |
2081.41 |
210.39 |
10.37 |
18.93 |
StrikeSwinging |
5.97 |
0.87 |
5.10 |
7.0 |
Changeup |
81.01 |
1374.24 |
248.57 |
12.45 |
6.31 |
StrikeSwinging |
6.02 |
1.03 |
5.12 |
8.3 |
Four-Seam |
89.41 |
2048.68 |
220.67 |
13.23 |
16.64 |
InPlay |
5.91 |
0.92 |
4.97 |
7.4 |
Sinker |
88.52 |
2012.26 |
223.73 |
14.24 |
16.11 |
FoulBallNotFieldable |
5.93 |
0.99 |
5.06 |
7.5 |
Four-Seam |
89.99 |
2001.44 |
212.93 |
11.34 |
18.85 |
BallCalled |
5.90 |
1.07 |
4.82 |
7.1 |
Changeup |
83.20 |
1441.48 |
247.75 |
14.43 |
7.31 |
InPlay |
5.84 |
1.11 |
5.20 |
8.3 |
# 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\n')
## Total number of pitches thrown: 51
# Display the summary table
knitr::kable(pitch_summary, caption = 'Summary Pitch Table for Alekson')
Summary Pitch Table for Alekson
Changeup |
33.33% |
17 |
5 |
12 |
29.41% |
70.59% |
81.26 |
1582.63 |
6.16 |
14.86 |
252.18 |
8.4 |
5.86 |
1.14 |
5.01 |
Four-Seam |
25.49% |
13 |
2 |
11 |
15.38% |
84.62% |
89.38 |
2087.03 |
18.23 |
12.91 |
217.14 |
7.3 |
5.90 |
0.97 |
5.00 |
Sinker |
27.45% |
14 |
3 |
11 |
21.43% |
78.57% |
89.24 |
2094.60 |
16.16 |
14.87 |
225.02 |
7.5 |
5.89 |
1.00 |
5.06 |
Slider |
11.76% |
6 |
2 |
4 |
33.33% |
66.67% |
81.69 |
1921.80 |
4.80 |
-1.43 |
146.31 |
4.9 |
5.92 |
1.05 |
5.02 |
NA |
1.96% |
1 |
1 |
0 |
100.00% |
0.00% |
89.02 |
2064.19 |
NaN |
NaN |
NaN |
NaN |
6.09 |
1.03 |
5.33 |
# 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('Alekson maximum FB velocity:', max_fb_velocity, '\n')
## Alekson maximum FB velocity: 91.08
# Prepare data for plotting pitch locations
pitch_location_data <- Alekson_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 Alekson',
x = 'Horizontal Location (feet)',
y = 'Vertical Location (feet)',
color = 'Swing/Take',
shape = 'Chase') +
facet_wrap(~ AutoPitchType) + # Create individual graphs for each pitch type
geom_text(aes(x = -1.75, y = 5, label = 'RHH'), color = 'black', size = 3, hjust = 0) + # Label for RHH
geom_text(aes(x = 1.75, y = 5, label = 'LHH'), color = 'black', size = 3, hjust = 1) + # Label for LHH
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 Alekson',
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')
)
