# Filter the data for the pitcher Interdonato
Interdonato_data <- Newport65 %>%
  filter(Pitcher == "Interdonato, Reed")

# Create a detailed table for each pitch
detailed_pitch_table <- Interdonato_data %>%
  select(AutoPitchType, RelSpeed, SpinRate, SpinAxis, HorzBreak, InducedVertBreak, PitchCall) %>%
  rename(
    ReleaseSpeed = RelSpeed,
    Tilt = SpinAxis,
    HorizontalBreak = HorzBreak,
    InducedVerticalBreak = InducedVertBreak
  ) %>%
  mutate(
    ReleaseSpeed = round(ReleaseSpeed, 2),
    SpinRate = round(SpinRate, 2),
    Tilt = round(Tilt, 2),
    HorizontalBreak = round(HorizontalBreak, 2),
    InducedVerticalBreak = round(InducedVerticalBreak, 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 Interdonato")
Detailed Pitch Table for Interdonato
AutoPitchType ReleaseSpeed SpinRate Tilt HorizontalBreak InducedVerticalBreak PitchCall ClockTilt
Sinker 92.14 2427.27 222.97 17.02 19.55 BallCalled 7.4
Sinker 92.08 2364.45 227.97 19.15 18.50 BallCalled 7.6
Sinker 91.99 2515.10 232.34 20.15 16.78 FoulBallNotFieldable 7.7
Slider 85.59 2423.41 51.14 -0.78 0.70 StrikeCalled 1.7
Slider 85.96 2478.22 169.98 -0.48 3.93 BallCalled 5.7
Four-Seam 92.86 2475.13 229.41 20.77 18.91 FoulBallNotFieldable 7.6
Four-Seam 94.35 2414.99 221.14 16.90 20.50 BallCalled 7.4
Four-Seam 92.44 2343.69 220.28 16.45 20.64 BallCalled 7.3
Four-Seam 92.93 2432.15 231.37 20.65 17.72 StrikeCalled 7.7
Slider 85.37 2486.99 169.60 -0.54 4.09 InPlay 5.7
Slider 86.17 2471.32 172.32 -0.47 4.87 StrikeCalled 5.7
Slider 85.31 2419.43 183.83 0.20 4.43 FoulBallNotFieldable 6.1
Sinker 92.93 2373.84 236.43 22.39 16.13 StrikeSwinging 7.9
Slider 84.55 2377.19 186.04 0.26 3.99 StrikeCalled 6.2
Slider 85.83 2463.83 160.26 -1.87 6.63 StrikeCalled 5.3
Slider 87.24 2426.34 181.58 0.10 5.40 BallCalled 6.1
Four-Seam 93.91 2316.23 221.09 16.12 19.66 BallCalled 7.4
Slider 87.02 2477.04 191.70 0.81 5.46 StrikeSwinging 6.4
Sinker 93.47 2426.87 235.00 21.23 16.09 InPlay 7.8
Sinker 93.16 2365.15 231.49 20.28 17.35 BallCalled 7.7
Slider 85.48 2410.24 180.81 0.05 5.19 BallCalled 6.0
Sinker 92.96 2367.15 234.26 21.27 16.56 StrikeCalled 7.8
Sinker 93.69 2229.25 235.58 20.50 15.28 FoulBallNotFieldable 7.9
Changeup 87.76 1668.48 247.98 16.32 7.76 InPlay 8.3
Sinker 90.80 2489.16 233.52 22.76 18.02 StrikeCalled 7.8
Slider 84.04 2451.02 192.78 1.06 5.85 BallCalled 6.4
Sinker 91.39 2505.83 234.73 20.90 15.89 StrikeSwinging 7.8
Slider 86.21 2423.59 195.39 0.91 4.46 StrikeSwinging 6.5
Sinker 89.63 2378.05 237.43 21.66 15.04 BallCalled 7.9
Sinker 92.32 2522.84 239.15 23.20 14.98 StrikeCalled 8.0
Changeup 86.03 2002.51 238.82 18.05 12.13 BallCalled 8.0
Slider 84.46 2408.46 189.42 0.74 5.54 FoulBallNotFieldable 6.3
Four-Seam 92.70 2476.43 225.60 20.01 20.84 FoulBallNotFieldable 7.5
Sinker 92.31 2499.47 236.52 20.43 14.70 StrikeSwinging 7.9
Slider 83.60 2345.92 165.24 -1.39 6.46 StrikeCalled 5.5
Slider 86.35 2441.13 208.66 2.72 6.61 BallCalled 7.0
Slider 86.32 2451.17 211.08 1.48 4.11 InPlay 7.0
Sinker 90.12 2496.63 225.15 18.49 19.67 FoulBallNotFieldable 7.5
Slider 83.73 2382.15 215.42 3.29 5.91 BallCalled 7.2
Sinker 91.41 2488.20 230.75 21.52 18.84 BallCalled 7.7
Slider 85.07 2414.51 212.71 2.86 6.09 InPlay 7.1
Sinker 90.70 2496.89 226.09 19.95 20.48 BallCalled 7.5
Sinker 91.09 2428.64 226.02 18.38 18.99 BallCalled 7.5
Four-Seam 91.62 2384.52 231.53 19.83 16.92 BallCalled 7.7
Sinker 91.32 2520.51 230.83 21.46 18.76 StrikeCalled 7.7
Sinker 92.06 2502.76 228.17 20.93 20.00 BallCalled 7.6
Sinker 91.22 2545.74 227.72 20.46 19.83 FoulBallNotFieldable 7.6
Slider 85.38 2382.06 160.43 -2.44 8.43 StrikeSwinging 5.3
Slider 85.85 2483.88 168.87 -0.99 6.32 BallCalled 5.6
Slider 86.19 2283.87 174.42 -0.64 7.81 BallCalled 5.8
Sinker 92.02 2354.87 226.01 19.74 20.29 FoulBallNotFieldable 7.5
Slider 85.86 2355.30 230.30 3.03 3.76 BallCalled 7.7
Four-Seam 92.84 2514.36 229.84 20.59 18.55 StrikeCalled 7.7
Slider 86.54 2454.37 196.72 1.66 6.90 StrikeCalled 6.6
Four-Seam 92.38 2489.85 230.22 19.77 17.67 StrikeSwinging 7.7
Four-Seam 92.89 2455.72 218.15 16.21 21.84 BallCalled 7.3
Slider 85.77 2324.71 213.61 2.86 5.55 BallCalled 7.1
Slider 88.21 2387.25 236.44 2.44 2.87 BallCalled 7.9
Slider 87.76 2408.95 226.61 3.22 4.23 StrikeSwinging 7.6
# Create a summary table
pitch_summary <- detailed_pitch_table %>%
  group_by(AutoPitchType) %>%
  summarise(
    TotalPitches = n(),
    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
  )

# Display the summary table
knitr::kable(pitch_summary, caption = "Summary Pitch Table for Interdonato")
Summary Pitch Table for Interdonato
AutoPitchType TotalPitches Balls Strikes BallPercentage StrikePercentage AvgVelocity AvgSpinRate AvgInducedVertBreak AvgHorzBreak AvgTilt AvgClockTilt
Changeup 2 1 1 50.00% 50.00% 86.90 1835.49 9.95 17.19 243.40 8.2
Four-Seam 10 5 5 50.00% 50.00% 92.89 2430.31 19.32 18.73 225.86 7.5
Sinker 21 8 13 38.10% 61.90% 91.85 2442.79 17.70 20.57 231.34 7.7
Slider 26 11 15 42.31% 57.69% 85.76 2416.63 5.22 0.70 186.36 6.2
# Prepare data for plotting pitch locations
pitch_location_data <- Interdonato_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 = 0.9) + # Adjust ratio to shrink vertical distance
  labs(title = "Pitch Locations for Interdonato",
       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 Interdonato",
       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")
  )