3

I am creating a map that consists out of 3 map panels. I have set the inner margins to zero in the tm_layout options for all maps, however depending on the dimensions of the output I still have empty white space inside the map frames.

enter image description here

I can reduce it to a minimum if I adjust the setting for width and height with tm_save but I want a clean solution.

I tried to creat a minimum example with the pre-installed tmap package data (though it is here less obvious that there is empty white space):

rm(list=ls(all=TRUE))
library(tmap)
data("NLD_prov")
map1 <- tm_shape(NLD_prov)+tm_fill()+tm_layout(inner.margins = c(0,0,0,0))
map2 <- tm_shape(NLD_prov)+tm_fill()+tm_layout(inner.margins = c(0,0,0,0))

final_map <-tmap_arrange(map1, map2)
final_map

In the original code I have cropped the input shape file to my desired map extent and also used a bounding box but that does not help:

 map_extent<-st_bbox(c(xmin = 8, xmax = 9.1,ymin = 53.8, ymax = 55.1), 
                  crs = st_crs(data))
 data_cropped<-crop_shape(data, map_extent, polygon = TRUE)

 tm_shape(data_cropped, bbox = map_extent)+
 ...

How can I force the margins to zero?

Kanoet
  • 143
  • 1
  • 11
  • Isn't the white space on top and below expected because of the aspect ratio? As you already mentioned, you can adjust that with `tmap_save`'s width and height arguments. If you need to also adjust the space between the facets, you could convert your `tmap` objects to `gTree` with `grid::grid.grab` and then use `cowplot::plot_grid` to arrange the plots in a way that reduces the space between them. If the idea is helpful/what you might look for, then I could post a answer. Easier would be to use small multiples - check also [this](http://von-tijn.nl/tijn/research/presentations/tmap_user2015.pdf) – Valentin_Ștefan Jan 27 '19 at 20:56
  • 1
    Thanks, indeed if I set asp=NA in tmap_arrange the margin sticks to the extent of the map or the bounding box if given. – Kanoet Feb 04 '19 at 14:21

0 Answers0