Tmap: Hi I have 3 diferent maps and I want to show them alltogether. Thus I perform the tm_arrange function and it works properly.

Created on 13 Oct 2020  路  8Comments  路  Source: mtennekes/tmap

question

All 8 comments

Hi I have 3 diferent maps and I want to show them alltogether. Thus I perform the tm_arrange function and it works properly. But now I want to add a main title in common for the three maps. For that porpouse I'm using the next script
tmap_arrange (map_IA14D, map_IA14H, map_IA14T) tmap_arrange (map_IA14D, map_IA14H, map_IA14T, outer.margins = NULL) + tm_layout(main.title = " IA14 del 7 al 20 de setembre ")
The first tmap_arrange is the one that works. But when I add the tm_layout I get the next error message:
"Error in tmap_arrange(map_IA14D, map_IA14H, map_IA14T, outer.margins = NULL) + :
argumento no-num茅rico para operador binario"

Thank you!!

Sorry, I haven't pase properly the code.
It should be as it follows:
tmap_arrange (map_IA14D, map_IA14H, map_IA14T) This one works (whithout the title)
tmap_arrange (map_IA14D, map_IA14H, map_IA14T, outer.margins = NULL) + tm_layout(main.title = " IA14 del 7 al 20 de setembre ") This one doesn't

@PauGallesClara please create a reproducible example (https://www.tidyverse.org/help/). It will help us help you.

It's not possible to add a main title to tmap_arrange, since tmap_arrange only combines tmap plots (nothing more).
A workaround is something like this:

library(tmap)
data(World)
tm1 <- qtm(World, fill = "HPI") + tm_layout(main.title = "Test")
tm2 <- qtm(World, fill = "well_being")
tm3 <- qtm(World, fill = "economy")

tmap_arrange(tm1, tm2, tm3, outer.margins = 0, ncol = 1)

Created on 2020-10-16 by the reprex package (v0.3.0)

Agree with @Nowosad suggestion to use a reproducible example next time. Also recommended to use reprex so that we can see the output directly in github.

@mtennekes also related - https://github.com/mtennekes/tmap/issues/338. Complete tmap_grob() function could help with this issue.

Hi !! I've been playing with your recomendations.
As it happens with the 3 world maps made by @mtennekes, the one that has the main title is a bit different than the others. So, I'm afraid that It's not a good option. Is there any way to fix that?
I've also tried the tmap_grob() without luck!!
I've decided to keep it without a main tittle

Sorry, for not being more clear with the sintax and the resulting maps, but I'm not sure that I can publish this kind of data yet. (Hope you understand). But in any case your advices have been very helpful!!

Many Thanks,
Pau

Hi Pau,
an alternative approach to this problem would be to use the grid package:

library(tmap)
library(grid)
data(World)
tm1 <- qtm(World, fill = "HPI")
tm2 <- qtm(World, fill = "well_being")
tm3 <- qtm(World, fill = "economy")

# by rows -----------------------------------------------------------------
grid.newpage()
pushViewport(viewport(layout = grid.layout(
        nrow = 4,
        ncol = 1,
        heights = c(0.1, 0.3, 0.3, 0.3))))
grid.text("Title", vp = viewport(layout.pos.row = 1))
print(tm1, vp = viewport(layout.pos.row = 2))
print(tm2, vp = viewport(layout.pos.row = 3))
print(tm3, vp = viewport(layout.pos.row = 4))


# by cols -----------------------------------------------------------------
grid.newpage()
pushViewport(viewport(layout = grid.layout(
        nrow = 2,
        ncol = 3,
        heights = c(0.1, 0.9))))
grid.text("Title", vp = viewport(layout.pos.row = 1, layout.pos.col = 1:3))
print(tm1, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(tm2, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
print(tm3, vp = viewport(layout.pos.row = 2, layout.pos.col = 3))

Created on 2020-10-17 by the reprex package (v0.3.0)

Hi !!

With your recomendations now I have different solutions, now I must choose the one it fits better.

Many thanks!!

Was this page helpful?
0 / 5 - 0 ratings