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

1

8

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"
    )
Brigitta answered 22/4, 2020 at 0:32 Comment(0)
R
13

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

Reena answered 22/4, 2020 at 5:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.