17  tmap options

library(tmap)
library(stars)
worldelevation = read_stars("data/worldelevation.tif")

17.1 Raster resolution

Raster data is represented by a grid of cells (Section 2.2.2), and the number of cells impacts the time to render a map. Rasters with hundreds of cells will be plotted quickly, while rasters with hundreds of millions or billions of cells will take a lot of time (and RAM) to be shown. Therefore, the tmap package downsamples large rasters by default to be below 10,000,000 cells in the plot mode and 1,000,000 cells in the view mode. This values can be adjusted with the raster.max_cells argument of tmap_options(), which expects a named vector with two elements - plot and view (Figure 17.1).

tmap_options(raster.max_cells = c(plot = 5000, view = 2000))
tm_shape(worldelevation) +
  tm_raster("worldelevation.tif")
Figure 17.1: A raster map with the decreased resolution

17.2 Resetting the options

Any tmap options can be reset (set to default) with tmap_options_reset().