Search code examples
rtmap

How to put title of a map outside of the panel (tmap package)


I'm plotting a simple map in R and I'm stuck with this problem: the title is overlapping the plot and I don't know how to put it outside of the panel.

brasil

With ggplot2 I can do this easily with plot.title.position option in theme function, since tmap works with the same logic, I think might be a way to do this.

Code and shapefile download:

library(sf)
library(tmap)

brasil <- st_read("/shp/BRUFE250GC_SIR.shp")

tm_shape(brasil) +
    tm_borders() +
    tm_fill() +
    tm_compass() +
    tm_scale_bar() +
    tm_layout(
        title = "The quick brown fox jumps over the lazy dog"
    )

Solution

  • Use tm_layout(main.title = "Main Title", main.title.position = "center") in place of tm_layout(title = "The quick brown fox jumps over the lazy dog") to have the title outside the map.

    tm_shape(brasil) +
      tm_borders() +
      tm_fill() +
      tm_compass() +
      tm_scale_bar() +
      tm_layout(
        main.title = "The quick brown fox jumps over the lazy dog", 
        main.title.position = "center")
    

    enter image description here