library(tidyverse)
library(R.utils)
library(httr)
library(sf)
Overview
This Ireland Map
explore the population density in the area. Data is from the latest version of Kontur Population
available at United Nations Humanitarian Data Exchange (HDX)
.
Download and unzip kontur
data: 20231101
<- "ireland-population.gpkg.gz" file_name
<-"https://geodata-eu-central-1-kontur-public.s3.amazonaws.com/kontur_datasets/kontur_population_IE_20231101.gpkg.gz"
url <- function() {
get_population_data <- httr::GET(
res
url,write_disk(file_name),
progress()
)
::gunzip(file_name, remove = F)
R.utils
}get_population_data()
<- gsub(".gz", "", file_name) load_file_name
<- sf::st_read(load_file_name) ie_sf
<- ie_sf%>%
ie_sf_lonlat st_as_sf(crs = "+proj=utm +zone=29") %>%
st_transform(crs = "+proj=longlat +datum=WGS84")
%>%
ie_sf_lonlatst_bbox()
First raw image: Ireland population data Kontur (2023-11-01)
ggplot() +
geom_sf(
data = ie_sf_lonlat,
aes(color = population),
lwd=0.1)
<- ie_sf_lonlat %>%
ie_geo st_geometry()
<- st_make_grid(ie_geo,
hexgrid cellsize = 1e4,
what = 'polygons',
square = FALSE ## !
%>%
) st_as_sf(crs = "+proj=utm +zone=29")%>%
st_transform(crs = "+proj=longlat +datum=WGS84")
<- hexgrid[c(unlist(st_contains(ie_geo, hexgrid)),
hexgrid2 unlist(st_overlaps(ie_geo, hexgrid))) ,]
List of Cities, boroughs and towns up to 2014:
<- read.csv("data/ie.csv")
ireland_cities_tb %>%head ireland_cities_tb
<- ireland_cities_tb%>%
ie_cities_sf st_as_sf(coords=c("lng","lat"),crs="+proj=longlat +datum=WGS84")
%>%summary()
ie_cities_sf
<-ie_cities_sf%>%
ie_cities_sffilter(!is.na(population))
Fonts
library(sysfonts)
library(showtext)
::font_add_google("Ubuntu Condensed","Ubuntu Condensed")
sysfonts<-"Ubuntu Condensed"
text::showtext_auto()
showtext::showtext_opts(dpi=320)
showtextlibrary(ggspatial)
set.seed(20231129)
<- ggplot() +
p geom_sf(data = ie_sf_lonlat,
mapping=aes(color = population),
lwd=0.1)+
scale_color_gradient(low = alpha("#cdbdcc",0.01),
high = "#a60845",
guide = "none")+
::new_scale_color()+
ggnewscalegeom_sf_text(data=ie_cities_sf,
mapping=aes(label=city,
color=population,
size=population),
show.legend = F,
family=text,
check_overlap = T)+
scale_color_gradient(low = alpha("#c2bfbf",0.9),high = "#a60845",)+
coord_sf(clip="off")+
::theme_map()+
ggthemestheme(text=element_text(family=text),
plot.caption = element_text(hjust = 0.5),
legend.background = element_blank(),
legend.position = "none",
legend.key.size = unit(7,units = "pt"),
legend.text = element_text(size=7))+
::annotation_north_arrow(location = "bl",
ggspatialwhich_north = "true",
pad_x = unit(-0.9, "cm"),
pad_y = unit(0.4, "cm"),
height = unit(0.8, "cm"),
width = unit(0.8, "cm"),
style = north_arrow_fancy_orienteering)+
::annotation_scale(pad_x = unit(-0.9, "cm"),
ggspatialheight = unit(0.18, "cm"),
text_family=text,
text_cex = 0.5)+
labs(caption="Cities by population density")
p
<- ggplot() +
p1geom_sf(data = ie_sf_lonlat,
mapping=aes(color = population),
lwd=0.5)+
scale_color_gradient(low = alpha("#cdbdcc",0.01),high = "#a60845",guide=guide_colorbar(title = "Population"))+
labs(caption="Country population density")+
::theme_map()+
ggthemestheme(text=element_text(family=text),
plot.caption = element_text(hjust = 0.5),
legend.background = element_blank(),
legend.position = c(0.95,0.1),
legend.key.size = unit(6,units = "pt"),
legend.title = element_text(size=6.1),
legend.text = element_text(size=7))
p1
library(cowplot)
ggdraw()+
draw_plot(p,x=-0.2,y=0)+
draw_plot(p1,x=0.2,y=0)+
draw_label(label="Ireland",
x=0.1,y=0.93,
size=25,
fontfamily=text,
fontface = "bold")+
draw_label(label="Kontur population density 2023-11-01\n#30DayMapChallenge 2023 Day 29: Population\nMap: @fgazzelloni",
x=0.55,y=0.93,
size=5,
fontfamily=text,
fontface = "bold")
ggsave("day29_population.png",bg="#f6f7f9")