1

I am using R package tmap to plot maps with multiple facets, using tm_facets().

It seems like space is not maximally used: there is a lot of blank/unused space on the resulting plot. Is that a constraint due to the specific size of my maps, or can I adjust it with some parameters?

library(tmap)
library(tidyverse)
data(metro)
metro_long <- metro %>% 
  gather(year, population, starts_with("pop"))


metro_long %>% 
  mutate(population = log(population)) %>% 
  filter(year %in% c("pop2010", "pop2020", "pop2030")) %>% 
  tm_shape()+
  tm_dots("population", size = 0.2, legend.is.portrait = FALSE) +
  tm_facets("year") +
  tm_layout(legend.outside.position =  "bottom" )
#> Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3

0

The argument to set this is legend.outside.size. The default depends on which style is used, but for the default style, the value is 0.3 (check tmap_options()$legend.outside.size).

Setting this to a smaller 0.1 value will make the legend take less space. Note however that the font of the legend is also reduced though, so there's a trade-off in the ideal legend.outside.size value.

library(tmap)
library(tidyverse)
data(metro)
metro_long <- metro %>% 
  gather(year, population, starts_with("pop"))

tm_default <- metro_long %>% 
  mutate(population = log(population)) %>% 
  filter(year %in% c("pop2010", "pop2020", "pop2030")) %>% 
  tm_shape()+
  tm_dots("population", size = 0.2, legend.is.portrait = FALSE) +
  tm_facets("year", nrow=3) +
  tm_layout(legend.outside.position =  "bottom", main.title="Default size (0.3)")

tm_small <- tm_default+ tm_layout(legend.outside.size=0.1,
                                  main.title="Manual size 0.1")

tmap_arrange(tm_default, tm_small)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.