mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
update ggrepel labels
This commit is contained in:
+45
-14
@@ -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") +
|
||||
|
||||
Reference in New Issue
Block a user