From 14ab17902139582a7d42837b3b6758c1232f32ce Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Fri, 2 Jan 2026 18:49:41 -0500 Subject: [PATCH] update ggrepel labels --- app/storm_report.qmd | 59 +++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/app/storm_report.qmd b/app/storm_report.qmd index 59da3c2..9751794 100644 --- a/app/storm_report.qmd +++ b/app/storm_report.qmd @@ -467,6 +467,8 @@ for(lf in unique_lf_ids) { #| fig-align: "left" for(lf in unique_lf_ids) { + lf_split <- split_full_lf_id(lf) + growth <- get_normalized_metric_growth(storm, lf) %>% mutate( population_opacity = rescale( @@ -518,7 +520,6 @@ for(lf in unique_lf_ids) { base_growth_map <- ggplot() + geom_sf(data = world, fill = "#e5e5e5", color = "#999999", size = 0.3) + geom_sf(data = states, fill = NA, color = "#cccccc", size = 0.2) + - geom_sf_label(data = growth_sf, aes(label = growth_sf$name)) + coord_sf( xlim = c(lon_range[1] - lon_padding, lon_range[2] + lon_padding), ylim = c(lat_range[1] - lat_padding, lat_range[2] + lat_padding), @@ -531,24 +532,29 @@ for(lf in unique_lf_ids) { theme_minimal() + plot_theme + set.seed(2004) h_growth_map <- base_growth_map + geom_sf(data = growth_sf, fill = "blue", color = "#e5e5e5", size = 0.5, alpha = growth_sf$housing_opacity) + - geom_sf_label(data = growth_sf, aes(label = growth_sf$name)) + + ggrepel::geom_label_repel( + data = growth_sf, + aes(label = name, geometry = geom_wkt), + stat = "sf_coordinates" + ) + labs( title = paste(lf, "Housing Growth Map By County"), ) + coord_sf( xlim = c(lon_range[1] - lon_padding, lon_range[2] + lon_padding), ylim = c(lat_range[1] - lat_padding, lat_range[2] + lat_padding), - expand = FALSE + expand = FALSE ) latest_opacity <- growth %>% filter(year == max(year)) %>% - select(county_fips, name, housing_opacity, population_opacity) + select(name, housing_opacity, population_opacity) growth_colored <- growth %>% - left_join(latest_opacity, by = c("county_fips", "name"), suffix = c("", "_latest")) + left_join(latest_opacity, by = "name", suffix = c("", "_latest")) housing_colors <- latest_opacity %>% distinct(name, housing_opacity) %>% @@ -565,15 +571,25 @@ for(lf in unique_lf_ids) { h_plot <- ggplot(growth_colored, aes(x = year, y = normalized_housing, color = name, - group = county_fips)) + + group = name)) + geom_line() + scale_color_manual(values = housing_color_values) + geom_text_repel( data = growth_colored %>% filter(year == max(year)), - aes(label = name, x = year + 1), + aes(label = name), direction = "y", hjust = 0, - size = 3 + size = 3, + color = "black", + segment.size = .5, + segment.alpha = .5, + segment.linetype = "dotted", + box.padding = .4, + segment.curvature = -0.1, + segment.ncp = 3, + segment.angle = 20, + min.segment.length = 0, + xlim = c(max(growth_colored$year), NA) ) + coord_cartesian(clip = "off") + guides(color = "none") + @@ -589,16 +605,21 @@ for(lf in unique_lf_ids) { print(h_growth_map) print(h_plot) + set.seed(2004) p_growth_map <- base_growth_map + geom_sf(data = growth_sf, fill = "red", color = "#e5e5e5", size = 0.5, alpha = growth_sf$population_opacity) + - geom_sf_label(data = growth_sf, aes(label = growth_sf$name)) + + ggrepel::geom_label_repel( + data = growth_sf, + aes(label = name, geometry = geom_wkt), + stat = "sf_coordinates" + ) + labs( title = paste(lf, "Population Growth Map By County"), - ) + + ) + coord_sf( xlim = c(lon_range[1] - lon_padding, lon_range[2] + lon_padding), ylim = c(lat_range[1] - lat_padding, lat_range[2] + lat_padding), - expand = FALSE + expand = FALSE ) population_colors <- latest_opacity %>% @@ -616,15 +637,25 @@ for(lf in unique_lf_ids) { p_plot <- ggplot(growth_colored, aes(x = year, y = normalized_population, color = name, - group = county_fips)) + + group = name)) + geom_line() + scale_color_manual(values = population_color_values) + geom_text_repel( data = growth_colored %>% filter(year == max(year)), - aes(label = name, x = year + 1), + aes(label = name), direction = "y", hjust = 0, - size = 3 + size = 3, + color = "black", + segment.size = .5, + segment.alpha = .5, + segment.linetype = "dotted", + box.padding = .4, + segment.curvature = -0.1, + segment.ncp = 3, + segment.angle = 20, + min.segment.length = 0, + xlim = c(max(growth_colored$year), NA) ) + coord_cartesian(clip = "off") + guides(color = "none") +