mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
add pie chart for fatality data
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -243,7 +243,6 @@ ui <- page_navbar(
|
||||
)
|
||||
)
|
||||
),
|
||||
nav_panel("Perils"),
|
||||
nav_panel(
|
||||
"Fatality Map",
|
||||
layout_columns(
|
||||
@@ -262,9 +261,11 @@ ui <- page_navbar(
|
||||
layout_column_wrap(
|
||||
width = 1,
|
||||
card(
|
||||
plotlyOutput("fatality_heatmap", height = "100%")
|
||||
plotlyOutput("fatality_pie", height = "100%")
|
||||
),
|
||||
card()
|
||||
card(
|
||||
plotlyOutput("fatality_heatmap", height = "100%")
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user