add pie chart for fatality data

This commit is contained in:
2026-04-09 00:12:51 -04:00
parent 9093a10d0e
commit f05ef58e5c
2 changed files with 51 additions and 3 deletions
+47
View File
@@ -930,4 +930,51 @@ server <- function(input, output, session) {
) %>%
config(displayModeBar = FALSE)
})
output$fatality_pie <- renderPlotly({
data <- fatality_heatmap_data()
pie_data <- data %>%
mutate(
category = case_when(
fatality_type %in% c("wind", "tree_fall") ~ "Wind",
fatality_type %in% c("surf", "rip_current") ~ "Surf",
fatality_type == "freshwater_floods" ~ "Freshwater Flood",
fatality_type == "offshore" ~ "Offshore",
fatality_type == "storm_surge" ~ "Storm Surge",
fatality_type == "tornado" ~ "Tornado",
fatality_type == "unknown" ~ "Unknown",
TRUE ~ NA_character_
)
) %>%
filter(!is.na(category)) %>%
group_by(category) %>%
summarise(n = sum(n), .groups = "drop") %>%
filter(n > 0)
category_colors <- c(
"Wind" = "#cd2626",
"Surf" = "#4f94cd",
"Offshore" = "#5cacee",
"Storm Surge" = "#4682b4",
"Freshwater Flood" = "#36648b",
"Tornado" = "#8b1a1a",
"Unknown" = "#ffa500"
)
plot_ly(
data = pie_data,
labels = ~category,
values = ~n,
type = "pie",
marker = list(colors = unname(category_colors[pie_data$category])),
textinfo = "label+value",
hovertemplate = "%{label}: %{value}<extra></extra>"
) %>%
layout(
legend = list(orientation = "h", x = 0.5, xanchor = "center", y = -0.1),
margin = list(l = 10, r = 10, t = 10, b = 10)
) %>%
config(displayModeBar = FALSE)
})
}