Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bydata committed Nov 9, 2024
1 parent 2f13794 commit 327a8e2
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions R/08-hdx.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
library(tidyverse)
library(terra)
library(sf)
library(ggspatial)
library(ggtext)

data_path <- file.path("data", "HDX")
Expand All @@ -23,7 +22,7 @@ downsample_raster <- function(raster, factor = 25) {
raster_downsampled_pop_full <- downsample_raster(rasters[[1]])
raster_downsampled_pop_group <- downsample_raster(rasters[[4]])

# Combine by division
# Combine the rasters: calculate the share of the subgroup
raster_downsampled_combined <- raster_downsampled_pop_group / raster_downsampled_pop_full

# Transform to a data.frame for ggplot
Expand All @@ -33,6 +32,7 @@ raster_downsampled_combined_df <- as.data.frame(
rename(population = `Population Count`) |>
mutate(population = replace_na(population, 0))

# Set breaks and labels for the contours
contour_breaks <- seq(
floor(min(raster_downsampled_combined_df$population) * 100) / 100,
ceiling(max(raster_downsampled_combined_df$population) * 100) / 100, 0.02)
Expand All @@ -48,7 +48,6 @@ p <- raster_downsampled_combined_df |>
geom_contour_filled(
aes(x, y, z = population),
breaks = contour_breaks) +
# scale_fill_viridis_d(labels = contour_labels) +
scale_fill_brewer(labels = contour_labels, direction = -1) +
coord_sf(crs = raster_crs) +
guides(fill = guide_legend(
Expand All @@ -69,7 +68,6 @@ p <- raster_downsampled_combined_df |>
plot.background = element_rect(color = "transparent", fill = "#121212"),
text = element_text(color = "#FCFCFC"),
legend.position = "bottom",
# legend.position.inside = c(1.15, 0.25),
legend.key.width = unit(3.5, "mm"),
legend.key.height = unit(3.5, "mm"),
legend.title = element_markdown(size = 7, lineheight = 1.1),
Expand Down

0 comments on commit 327a8e2

Please sign in to comment.