0

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?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Sean
  • 47
  • 6

1 Answers1

0

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

mgrund
  • 1,415
  • 8
  • 10
  • Hi would you also know how to out these values in percentages? i.e. when you click on a specfic area. It will show the population of 0-14, 15-24 in relation to a percentage of each other? e.g. You click on the bottom area and of the total there are 10% 0-14, 30% 15-24, 70% 25-44 – Sean Aug 05 '21 at 09:27