'How to display the legend only once when using tmap::tm_facets() in view mode?

I made a map using the tmap package. This map is displayed in view mode and has facets. I would like the legend to appear only once, outside of the graph/facets, at the bottom and stacked horizontally.

I cannot share the original data but here is a hopefully reproducible example:

library(tmap)
library(tmaptools)

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

tmap_mode("view")

map <- tm_shape(NLD_muni) +
  tm_borders() +
  tm_facets(by="province", free.scales = F) +
  tm_fill("population", style="kmeans", convert2density = TRUE) +
  tm_shape(NLD_prov) +
  tm_borders(lwd=4) +
  tm_facets(by="name") +
  tm_legend(legend.outside = T, legend.stack = "horizontal", legend.outside.position = 'bottom')
map

You can see in tm_legend() what I have already tried, to no avail. Would anybody have any pointers?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source