Spaces:
Running
Running
Update app.R
Browse files
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(
|
| 155 |
-
mutate(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"),
|