igroffman commited on
Commit
de44029
·
verified ·
1 Parent(s): f69814f

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +6 -5
app.R CHANGED
@@ -146,13 +146,14 @@ create_at_bats_plot <- function(batter_data, player_name, game_key, pitch_colors
146
  ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5, size = 14, face = "bold")))
147
  }
148
 
149
- df <- df %>%
150
- rename(TopBottom = `Top/Bottom`) # Add this at the start of the function
151
-
152
  plot_data <- df %>%
153
  arrange(PitchNo) %>%
154
- group_by(Inning, TopBottom, PAofInning) %>%
155
- mutate(pa_number = dplyr::cur_group_id()) %>%
 
 
 
 
156
  ungroup() %>%
157
  mutate(
158
  PlayResult = na_if(str_squish(PlayResult), "Undefined"),
 
146
  ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5, size = 14, face = "bold")))
147
  }
148
 
 
 
 
149
  plot_data <- df %>%
150
  arrange(PitchNo) %>%
151
+ group_by(Batter) %>%
152
+ mutate(
153
+ pa_change = (PAofInning != lag(PAofInning, default = 0)) |
154
+ (Inning != lag(Inning, default = 0)),
155
+ pa_number = cumsum(pa_change)
156
+ ) %>%
157
  ungroup() %>%
158
  mutate(
159
  PlayResult = na_if(str_squish(PlayResult), "Undefined"),