igroffman commited on
Commit
ea29211
·
verified ·
1 Parent(s): ed697ce

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +16 -23
app.R CHANGED
@@ -2969,7 +2969,6 @@ umpire_create_report_pdf <- function(data,
2969
  suppressPackageStartupMessages({
2970
  library(dplyr); library(grid); library(gridExtra); library(ggplot2); library(stringr)
2971
  })
2972
-
2973
  `%||%` <- function(a, b) if (!is.null(a)) a else b
2974
 
2975
  raw_strike_miss <- data %>%
@@ -2987,21 +2986,14 @@ umpire_create_report_pdf <- function(data,
2987
  correct <- total_called - total_missed
2988
  overall_pct <- paste0(sprintf("%.0f", 100 * (correct / total_called)), "%")
2989
 
2990
- buffer_strike_miss <- data %>%
2991
- filter(PitchCall == "StrikeCalled") %>%
2992
- filter(PlateLocSide < -0.9975 | PlateLocSide > 0.9975 |
2993
- PlateLocHeight > 3.5 | PlateLocHeight < 1.3775) %>%
2994
- nrow()
2995
-
2996
- buffer_ball_miss <- data %>%
2997
- filter(PitchCall %in% c("BallCalled", "BallinDirt")) %>%
2998
- filter(PlateLocSide > -0.9975 & PlateLocSide < 0.9975 &
2999
- PlateLocHeight < 3.5 & PlateLocHeight > 1.3775) %>%
3000
- nrow()
3001
-
3002
- buffer_total_missed <- buffer_strike_miss + buffer_ball_miss
3003
- buffer_correct <- total_called - buffer_total_missed
3004
- buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_called)), "%")
3005
 
3006
  game_date <- suppressWarnings(format(max(as.Date(data$Date)), "%b %d, %Y"))
3007
  opp_team <- data %>% filter(BatterTeam != "COA_CHA") %>% pull(BatterTeam) %>% unique() %>% head(1)
@@ -3048,12 +3040,12 @@ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_call
3048
  ggplot() +
3049
  geom_rect(data = buffer_zone_rect,
3050
  aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
3051
- fill = NA, color = "gray50", linewidth = 0.4, linetype = "dotted") +
3052
  geom_rect(data = strike_zone_rect,
3053
  aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
3054
- fill = NA, color = "black", linewidth = 0.4) +
3055
  geom_polygon(data = home_plate, aes(x = x, y = y),
3056
- fill = NA, color = "gray40", linewidth = 0.4) +
3057
  coord_equal() +
3058
  scale_x_continuous(limits = c(-1.8, 1.8)) +
3059
  scale_y_continuous(limits = c(0, 4.5)) +
@@ -3081,7 +3073,7 @@ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_call
3081
  PlateLocHeight < 3.37750, PlateLocHeight > 1.5)
3082
  base_zone() +
3083
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3084
- pch = 21, fill = "#006F71", color = "black", size = 3) +
3085
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3086
  color = "white", size = 2.2, fontface = "bold") +
3087
  ggtitle(title_label)
@@ -3094,7 +3086,7 @@ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_call
3094
  PlateLocHeight > 3.37750 | PlateLocHeight < 1.5)
3095
  base_zone() +
3096
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3097
- pch = 21, fill = "#006F71", color = "black", size = 3) +
3098
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3099
  color = "white", size = 2.2, fontface = "bold") +
3100
  ggtitle(title_label)
@@ -3108,7 +3100,7 @@ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_call
3108
  PlateLocHeight < 3.37750, PlateLocHeight > 1.5)
3109
  base_zone() +
3110
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3111
- pch = 21, fill = "#006F71", color = "black", size = 3) +
3112
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3113
  color = "white", size = 2.2, fontface = "bold") +
3114
  ggtitle(title_label)
@@ -3122,7 +3114,7 @@ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_call
3122
  PlateLocHeight > 3.37750 | PlateLocHeight < 1.5)
3123
  base_zone() +
3124
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3125
- pch = 21, fill = "#006F71", color = "black", size = 3) +
3126
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3127
  color = "white", size = 2.2, fontface = "bold") +
3128
  ggtitle(title_label)
@@ -3304,6 +3296,7 @@ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_call
3304
  invisible(output_file)
3305
  }
3306
 
 
3307
  # Advanced Pitcher Functions
3308
  `%||%` <- function(a, b) if (!is.null(a)) a else b
3309
 
 
2969
  suppressPackageStartupMessages({
2970
  library(dplyr); library(grid); library(gridExtra); library(ggplot2); library(stringr)
2971
  })
 
2972
  `%||%` <- function(a, b) if (!is.null(a)) a else b
2973
 
2974
  raw_strike_miss <- data %>%
 
2986
  correct <- total_called - total_missed
2987
  overall_pct <- paste0(sprintf("%.0f", 100 * (correct / total_called)), "%")
2988
 
2989
+ buffer_strike_miss <- data %>%
2990
+ filter(PitchCall == "StrikeCalled") %>%
2991
+ filter(PlateLocSide < -0.9975 | PlateLocSide > 0.9975 |
2992
+ PlateLocHeight > 3.5 | PlateLocHeight < 1.3775) %>% nrow()
2993
+
2994
+ buffer_total_missed <- raw_ball_miss + buffer_strike_miss
2995
+ buffer_correct <- total_called - buffer_total_missed
2996
+ buffer_pct <- paste0(sprintf("%.0f", 100 * (buffer_correct / total_called)), "%")
 
 
 
 
 
 
 
2997
 
2998
  game_date <- suppressWarnings(format(max(as.Date(data$Date)), "%b %d, %Y"))
2999
  opp_team <- data %>% filter(BatterTeam != "COA_CHA") %>% pull(BatterTeam) %>% unique() %>% head(1)
 
3040
  ggplot() +
3041
  geom_rect(data = buffer_zone_rect,
3042
  aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
3043
+ fill = NA, color = "gray50", linewidth = 0.6, linetype = "dotted") +
3044
  geom_rect(data = strike_zone_rect,
3045
  aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),
3046
+ fill = NA, color = "black", linewidth = 0.8) +
3047
  geom_polygon(data = home_plate, aes(x = x, y = y),
3048
+ fill = NA, color = "gray40", linewidth = 0.5) +
3049
  coord_equal() +
3050
  scale_x_continuous(limits = c(-1.8, 1.8)) +
3051
  scale_y_continuous(limits = c(0, 4.5)) +
 
3073
  PlateLocHeight < 3.37750, PlateLocHeight > 1.5)
3074
  base_zone() +
3075
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3076
+ pch = 21, fill = "#006F71", color = "black", size = 5) +
3077
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3078
  color = "white", size = 2.2, fontface = "bold") +
3079
  ggtitle(title_label)
 
3086
  PlateLocHeight > 3.37750 | PlateLocHeight < 1.5)
3087
  base_zone() +
3088
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3089
+ pch = 21, fill = "#006F71", color = "black", size = 5) +
3090
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3091
  color = "white", size = 2.2, fontface = "bold") +
3092
  ggtitle(title_label)
 
3100
  PlateLocHeight < 3.37750, PlateLocHeight > 1.5)
3101
  base_zone() +
3102
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3103
+ pch = 21, fill = "#006F71", color = "black", size = 5) +
3104
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3105
  color = "white", size = 2.2, fontface = "bold") +
3106
  ggtitle(title_label)
 
3114
  PlateLocHeight > 3.37750 | PlateLocHeight < 1.5)
3115
  base_zone() +
3116
  geom_point(data = pts, aes(x = PlateLocSide, y = PlateLocHeight),
3117
+ pch = 21, fill = "#006F71", color = "black", size = 5) +
3118
  geom_text(data = pts, aes(x = PlateLocSide, y = PlateLocHeight, label = CallNo),
3119
  color = "white", size = 2.2, fontface = "bold") +
3120
  ggtitle(title_label)
 
3296
  invisible(output_file)
3297
  }
3298
 
3299
+
3300
  # Advanced Pitcher Functions
3301
  `%||%` <- function(a, b) if (!is.null(a)) a else b
3302