library(dplyr)
library(purrr)
library(ggplot2)
library(sf)
library(ggrepel)

Read in the shape files downloaded from GADM.

shpfiles <- paste0("gadm36_",
                   params$places,
                   "_0_sf.rds")

sfobjs <- map(shpfiles,
              ~ readr::read_rds(here::here("data/Geography",
                                           .x)))

Read in the weighted risks.

wtd_risk <- here::here(params$risk) %>%
    readr::read_csv() 

And join the data sets.

joined_df <- map(sfobjs,
                 function(x) {
                     left_join(x,
                               wtd_risk,
                               by = c("NAME_0" = "flow_to"))
                     })

Read in the centroids to place labels.

And plot.

p <- ggplot()
p <- p + scale_fill_distiller(palette = "Spectral",
                              name = "Relative Risk")
p <- p + xlab("") + ylab("")
p <- p + theme(
               panel.ontop = FALSE,
               panel.grid = element_blank(), 
               line = element_blank(), 
             rect = element_blank())

for (df in joined_df) {
    p <- p + geom_sf(data = df, aes(fill = wtd_rel_risk),
                     lwd = 0.1,
                     alpha = 0.8)
}
p <- p + coord_sf(datum = NA)
p

Place labels.

centroids <- readr::read_csv(here::here(params$centroids))
p1 <- p + geom_text_repel(data = centroids,
                          arrow = arrow(length = unit(0.03, "npc"),
                                        type = "closed",
                                        ends = "first"),
                          aes(label = ADM0,
                              x = Centroid_Lon,
                              y = Centroid_Lat),
                          size = 3,
                          fontface = "bold",
                          inherit.aes = FALSE)


annecori/mRIIDSprocessData documentation built on May 29, 2019, 1:16 p.m.