Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -2871,14 +2871,25 @@ create_count_usage_plot <- function(data, pitcher_name, pitch_colors) {
|
|
| 2871 |
pct_label = ifelse(percentage >= 2, paste0(round(percentage), "%"), "")
|
| 2872 |
) %>%
|
| 2873 |
dplyr::filter(total > 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2874 |
|
| 2875 |
plot_df$count <- factor(plot_df$count, levels = c("0-0", "Ahead", "Behind", "2 Strikes"))
|
| 2876 |
plot_df$BatterSide <- factor(plot_df$BatterSide, levels = c("Vs Left", "Vs Right"))
|
| 2877 |
-
|
| 2878 |
-
|
| 2879 |
-
|
| 2880 |
-
|
| 2881 |
-
|
|
|
|
| 2882 |
facet_grid(BatterSide ~ count, labeller = label_value, drop = FALSE) +
|
| 2883 |
ggtitle("Count Usage") +
|
| 2884 |
scale_fill_manual(values = pitch_colors, na.translate = FALSE) +
|
|
|
|
| 2871 |
pct_label = ifelse(percentage >= 2, paste0(round(percentage), "%"), "")
|
| 2872 |
) %>%
|
| 2873 |
dplyr::filter(total > 0)
|
| 2874 |
+
|
| 2875 |
+
plot_df <- plot_df %>%
|
| 2876 |
+
group_by(count, BatterSide) %>%
|
| 2877 |
+
arrange(TaggedPitchType) %>%
|
| 2878 |
+
mutate(
|
| 2879 |
+
ymax = cumsum(percentage),
|
| 2880 |
+
ymin = ymax - percentage,
|
| 2881 |
+
label_pos = (ymin + ymax) / 2
|
| 2882 |
+
) %>%
|
| 2883 |
+
ungroup()
|
| 2884 |
|
| 2885 |
plot_df$count <- factor(plot_df$count, levels = c("0-0", "Ahead", "Behind", "2 Strikes"))
|
| 2886 |
plot_df$BatterSide <- factor(plot_df$BatterSide, levels = c("Vs Left", "Vs Right"))
|
| 2887 |
+
|
| 2888 |
+
|
| 2889 |
+
ggplot(plot_df, aes(x = 1, y = percentage, fill = TaggedPitchType)) +
|
| 2890 |
+
geom_bar(width = 1, stat = "identity", color = "white") +
|
| 2891 |
+
geom_text(aes(y = label_pos, label = pct_label), size = 3) +
|
| 2892 |
+
coord_polar(theta = "y", start = 0) +
|
| 2893 |
facet_grid(BatterSide ~ count, labeller = label_value, drop = FALSE) +
|
| 2894 |
ggtitle("Count Usage") +
|
| 2895 |
scale_fill_manual(values = pitch_colors, na.translate = FALSE) +
|