library(tidyverse)
library(sf)
library(geographr)
library(viridis)
library(patchwork)
healthy_people_domain <-
read_csv("data/vulnerability/health-inequalities/wales/healthy-people-domain.csv")
shp <-
boundaries_lad %>%
filter(str_detect(lad_code, "^W"))
healthy_people_domain_shp <-
shp %>%
left_join(healthy_people_domain, by = "lad_code")
# White map theme
theme_map <- function(...) {
theme_minimal() +
theme(
text = element_text(family = "FiraCode-Retina", color = "#22211d"),
axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
# panel.grid.minor = element_line(color = "#ebebe5", size = 0.2),
panel.grid.major = element_line(color = "#ebebe5", size = 0.2),
panel.grid.minor = element_blank(),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA),
panel.border = element_blank(),
# Add labs elements
legend.title = element_text(size = 11),
legend.text = element_text(size = 9, hjust = 0),
plot.title = element_text(size = 15, hjust = 0.5),
plot.subtitle = element_text(
size = 10, hjust = 0.5,
margin = margin(
b = 0.2,
t = 0.2,
l = 2,
unit = "cm"
),
debug = F
),
# captions
plot.caption = element_text(
size = 7,
hjust = .5,
margin = margin(
t = 0.2,
b = 0,
unit = "cm"
),
color = "#939184"
),
...
)
}
healthy_people <-
healthy_people_domain_shp %>%
select(healthy_people_domain_quantiles, geometry) %>%
ggplot() +
geom_sf(
mapping = aes(fill = healthy_people_domain_quantiles),
color = "black",
size = 0.1
) +
scale_fill_viridis(
breaks = seq(1, 10, by = 1),
labels = seq(1, 10, by = 1),
na.value = "transparent",
option = "magma",
name = expression(paste("Healthy People \nDomain Deciles")),
alpha = 0.8, # make fill a bit brighter
begin = 0.1, # this option seems to be new (compared to 2016):
# with this we can truncate the
# color scale, so that extreme colors (very dark and very bright) are not
# used, which makes the map a bit more aesthetic
end = 0.9,
discrete = F, # discrete classes, thus guide_legend instead of _colorbar
direction = -1, # dark is lowest, yellow is highest
guide = guide_legend(
keyheight = unit(5, units = "mm"),
title.position = "top",
reverse = T
)
) +
theme_map() +
theme(plot.margin = unit(c(0.5, 1.5, 0.5, 1.5), "cm"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.