Skip to content

Instantly share code, notes, and snippets.

@BroVic
Created March 6, 2023 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BroVic/4d51382b8018d9a185c3410783918405 to your computer and use it in GitHub Desktop.
Save BroVic/4d51382b8018d9a185c3410783918405 to your computer and use it in GitHub Desktop.
Integrating `naijR::map_ng` with `tmap`
library(sf)
library(tmap)
# The output of `map_ng` is of class `map` is convertible
# to an object of class `sf`
ng_map <- naijR::map_ng(plot = FALSE)
ng_sf <- st_as_sfc(ng_map)
tm_shape(ng_sf) +
tm_polygons()
# Interactive map
tmap_mode("view")
tm_shape(ng_sf) + tm_polygons()
# Update the `sf` object by adding a variable of letters
alpha <- sample(LETTERS[1:6], length(ng_sf), replace = TRUE)
ng_sf <- st_sf(ng_sf, data.frame(alpha = alpha))
tm_shape(ng_sf) +
tm_polygons("alpha")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment