Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #TidyTuesday 2021 W46 Africa
- #libraries ----
- library(sf)
- library(ggspatial)
- library(showtext)
- library(patchwork)
- library(tidyverse)
- #data ----
- library(afrilearndata)
- library(afrihealthsites)
- #font ----
- font_add_google("Benchnine", "bench")
- font_add_google("Lexend Zetta", "lexend")
- #colour ----
- dark_colour <- "black"
- light_colour <- "white"
- #create continent shapes ----
- shape_1 <- africontinent %>%
- st_cast("POLYGON") %>%
- slice(1) %>%
- st_simplify(., dTolerance = 0.25)
- shape_2 <- africontinent %>%
- st_cast("POLYGON") %>%
- slice(1) %>%
- st_simplify(., dTolerance = 2)
- #country shapes ----
- countries <- africountries %>%
- filter(name %in% c("Dem. Rep. Congo", "Cameroon", "Nigeria")) %>%
- st_cast("POLYGON") %>%
- st_simplify(., dTolerance = 2)
- #panel 1: DR Congo ----
- shape_congo <- countries %>% filter(name == "Dem. Rep. Congo")
- health_congo <- afrihealthsites("Democratic Republic of the Congo", plot = "sf")
- p1 <- ggplot() +
- layer_spatial(shape_congo,
- colour = NA,
- fill = light_colour) +
- annotation_spatial(health_congo,
- shape = 15,
- size = 1,
- colour = dark_colour) +
- theme_void() +
- theme(plot.background = element_rect(colour = dark_colour, fill = dark_colour))
- #panel 2: Cameroon ----
- shape_cam <- countries %>% filter(name == "Cameroon")
- health_cam <- afrihealthsites("Cameroon", plot = "sf")
- p2 <- ggplot() +
- layer_spatial(shape_cam,
- colour = NA,
- fill = light_colour) +
- annotation_spatial(health_cam,
- shape = 15,
- size = 1,
- colour = dark_colour) +
- theme_void() +
- theme(plot.background = element_rect(colour = dark_colour, fill = dark_colour))
- #panel 3: Nigeria ----
- shape_nigeria <- countries %>% filter(name == "Nigeria")
- health_nigeria <- afrihealthsites("Nigeria", plot = "sf")
- p3 <- ggplot() +
- layer_spatial(shape_nigeria,
- colour = NA,
- fill = light_colour) +
- annotation_spatial(health_nigeria,
- shape = 15,
- size = 1,
- colour = dark_colour) +
- theme_void() +
- theme(plot.background = element_rect(colour = dark_colour, fill = dark_colour))
- #panel 4 ----
- p4 <- ggplot() +
- layer_spatial(countries,
- fill = dark_colour,
- colour = NA,
- show.legend = FALSE) +
- layer_spatial(shape_1,
- size = 3,
- fill = NA,
- colour = dark_colour) +
- layer_spatial(shape_2,
- size = 3,
- fill = NA,
- colour = dark_colour) +
- theme_void() +
- theme(plot.background = element_rect(colour = light_colour, fill = light_colour))
- #frame ----
- frame <- ggplot() +
- geom_polygon(aes(x = c(0, 0, 100, 100),
- y = c(0, 160, 160, 0)),
- colour = light_colour,
- fill = light_colour) +
- coord_fixed(expand = FALSE) +
- theme_void()
- #annotations ----
- showtext_auto()
- showtext_opts(dpi = 300)
- a1 <- ggplot() +
- annotate("rect", xmin = 5, ymin = 82, xmax = 49, ymax = 155,
- fill = dark_colour,
- colour = NA) +
- annotate("rect", xmin = 51, ymin = 82, xmax = 95, ymax = 155,
- fill = dark_colour,
- colour = NA) +
- annotate("rect", xmin = 5, ymin = 5, xmax = 49, ymax = 78,
- fill = light_colour,
- colour = NA) +
- annotate("rect", xmin = 51, ymin = 5, xmax = 95, ymax = 78,
- fill = dark_colour,
- colour = NA) +
- scale_x_continuous(limits = c(0, 100)) +
- scale_y_continuous(limits = c(0, 160)) +
- coord_cartesian(expand = FALSE) +
- theme_void()
- a2 <- ggplot() +
- annotate("text", x = 10, y = 73, label = "AFRICA\nRESPONDS",
- hjust = 0, vjust = 1,
- lineheight = 0.9,
- colour = dark_colour,
- family = "lexend",
- fontface = "bold",
- size = 4) +
- annotate("text", x = 10, y = 62, label = "Accurate healthcare location data is essential for a fast,\ncoordinated response to disease outbreaks.",
- hjust = 0, vjust = 1,
- colour = dark_colour,
- family = "bench",
- size = 2) +
- annotate("text", x = 10, y = 150, label = "NIGERIA",
- hjust = 0, vjust = 1,
- colour = light_colour,
- family = "lexend",
- size = 3) +
- annotate("text", x = 10, y = 143, label = "LASSA FEVER\n3,660 Health Sites",
- hjust = 0, vjust = 1,
- colour = light_colour,
- family = "bench",
- size = 4) +
- annotate("text", x = 55, y = 150, label = "CAMEROON",
- hjust = 0, vjust = 1,
- colour = light_colour,
- family = "lexend",
- size = 3) +
- annotate("text", x = 55, y = 143, label = "CHOLERA\n1,761 Health Sites",
- hjust = 0, vjust = 1,
- colour = light_colour,
- family = "bench",
- size = 4) +
- annotate("text", x = 55, y = 73, label = "DEMOCRATIC\nREPUBLIC\nOF THE\nCONGO",
- hjust = 0, vjust = 1,
- colour = light_colour,
- family = "lexend",
- size = 3) +
- annotate("text", x = 55, y = 20, label = "EBOLA VIRUS DISEASE\n2,739 Health Sites",
- hjust = 0, vjust = 1,
- colour = light_colour,
- family = "bench",
- size = 4) +
- annotate("rect", xmin = 5.5, ymin = 5.5, xmax = 48.5, ymax = 77.5,
- size = 1.5,
- fill = NA,
- colour = dark_colour) +
- annotate("text", x = 5, y = 2.5, label = "Source: WHO Weekly Bulletin (1-7 Nov 2021), afrimapr | #TidyTuesday 2021 W46 | | #30DayMapChallenge D9 | @quite_grey",
- hjust = 0,
- colour = dark_colour,
- family = "bench",
- size = 2) +
- scale_x_continuous(limits = c(0, 100)) +
- scale_y_continuous(limits = c(0, 160)) +
- coord_cartesian(expand = FALSE) +
- theme_void()
- #compile ----
- frame +
- inset_element(a1, 0, 0, 1, 1, align_to = "plot") +
- inset_element(p3, 5/100, 60/160, 45/100, 155/160,
- align_to = "plot") +
- inset_element(p2, 55/100, 70/160, 90/100, 155/160,
- align_to = "plot") +
- inset_element(p1, 58/100, 20/160, 90/100, 55/160,
- align_to = "plot") +
- inset_element(p4, 6/100, 5/160, 47/100, 60/160,
- align_to = "plot") +
- inset_element(a2, 0, 0, 1, 1, align_to = "plot")
- #save ----
- ggsave("./output/plot/africa_map_bw.png", height = 16, width = 10, unit = "cm")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement