Created
November 27, 2022 03:34
-
-
Save dakvid/9b31869c4578b5c48aa26142cf48d734 to your computer and use it in GitHub Desktop.
#30DayMapChallenge 2022 - Day 18 - Blue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Take the full Kontur dataset (if the machine can handle it) and show only those | |
# that match where I live | |
library(dplyr) | |
library(sf) | |
library(ggplot2) | |
# https://data.humdata.org/dataset/kontur-population-dataset | |
kontur <- | |
st_read("kontur_population_20220630.gpkg") | |
CRS_KONTUR <- st_crs(kontur) | |
home <- | |
tibble(lat = -40.869, long = 175.071) |> | |
st_as_sf(coords = c("long", "lat"), | |
crs = 4326) |> | |
st_transform(crs = CRS_KONTUR) | |
kontur_home <- | |
kontur |> | |
mutate(is_home = lengths(st_intersects(geom, home)) > 0) |> | |
filter(is_home) | |
home_population <- | |
kontur_home |> | |
pull(population) | |
kontur_same_pop <- | |
kontur |> | |
filter(population == home_population) | |
kontur_similar_pop <- | |
kontur |> | |
filter(population >= (home_population * 0.99), population <= (home_population * 1.01)) | |
ggplot() + | |
geom_sf(data = kontur_similar_pop, | |
fill = "light blue", colour = "light blue") + | |
geom_sf(data = kontur_same_pop, | |
fill = "dark blue", colour = "dark blue") + | |
theme_void() + | |
theme(plot.background = element_rect(fill = "white", colour = "white"), | |
panel.background = element_rect(fill = "white", colour = "white")) | |
ggsave("day_18_kontur_matches.png", | |
width = 2400, height = 1400, units = "px", | |
background = "white") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment