0

I have created an animated faceted map using tmap:: tm_facets along with custom panel labels. How do I avoid that the argument that is used to facet is shown as additional title? I only want the custom label in the panel.

Minimum example:

rm(list=ls(all=TRUE)) 
library(tmap)
library(spData)

urb_anim = tm_shape(world) + tm_polygons() + 
  tm_shape(urban_agglomerations) + tm_dots(size = "population_millions") +
  tm_facets(along = "year", free.coords = FALSE) +
  tm_layout(panel.labels = c("custom label1", "custom label2")) 

That gives me the following result: enter image description here

When I try to reproduce the example for an animated map from here: https://geocompr.robinlovelace.net/adv-map.html I also don't get the titles in a panel as in the example but outside the plot in the top left corner.

Kanoet
  • 143
  • 1
  • 11

1 Answers1

1

I found the answer myself:

Using the by instead of the along argument with tm_facets worked for me when setting ncol =1 and nrow = 1 and saving the the created map using tmap_animation. So the code should be:

urb_anim = tm_shape(world) + tm_polygons() + 
  tm_shape(urban_agglomerations) + tm_dots(size = "population_millions") +
  tm_facets(by = "year", free.coords = FALSE, ncol=1, nrow=1) +
  tm_layout(panel.labels = c("custom label1", "custom label2"))
Kanoet
  • 143
  • 1
  • 11
  • Could you add the final result here as an image? It is not clear what your objective is, i.e. what you managed to fix. – user3386170 Mar 02 '20 at 19:22