Created
March 6, 2023 17:06
-
-
Save BroVic/4d51382b8018d9a185c3410783918405 to your computer and use it in GitHub Desktop.
Integrating `naijR::map_ng` with `tmap`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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