rshinyr-sftmap

Is there a way to provide a relationship between many variables displayed in facets in tmap? E.g. showing multiple variables on one interactive map


I am trying to show the population of all different age groups in a map. Is there a way to show this information NOT in facets. But instead group together on a single interactive map?

Below is a reproducible example with the NLD_muni dataset on CRAN. The tmap part produced the different populations in facets. Just copy and paste:


library(spData)
library(spDataLarge)

data(World, Europe, NLD_muni, NLD_prov, land, metro)

tm_shape(NLD_muni) +
  tm_fill(c("pop_0_14", "pop_15_24", "pop_25_44", "pop_45_64", "pop_65plus"),
          style="kmeans", 
          palette=list("Oranges", "Greens", "Blues", "Purples", "Greys"),
          title=c("Population 0 to 14", "Population 15 to 24", "Population 25 to 44",
                  "Population 45 to 64", "Population 65 and older")) +
  tm_shape(NLD_muni) +
  tm_borders() 

I was potentially thinking if this is not possible in tmap. Is there a way to structure the dataset differently so i can do this?


Solution

  • Simply add:

    + tm_facets(as.layers = T)
    

    after tm_borders() and use view-mode via tmap_mode("view"). Then you can select the individual entries via the check boxes in the legend.

    enter image description here