Skip to contents

Modes

tmap facilitates two output modes: "plot", which produces static maps, and "view" which produces (using the same tmap code) interactive maps. As of version 4, tmap can also be extended with other modes, as demonstrated below.

Switching between modes

## current mode
tmap_mode()
#>  Current tmap mode is "plot".
#>  Call `tmap::ttm()` to switch mode.

## to view mode
tmap_mode("view")
#>  tmap mode set to "view".

## back to plot mode
tmap_mode("plot")
#>  tmap mode set to "plot".

The handy function ttm() is used to toggle between the modes.

Plot mode

We start with cerating the plot and assign it to a variable called tm.

tm = tm_shape(World, crs = 8857) +
  tm_polygons(
    fill = "press",
    fill.scale = tm_scale_intervals(values = "pu_gn")) +
tm_shape(metro) +
  tm_bubbles(
    size = "pop2020",
    fill = "gold",
    size.scale = tm_scale_continuous(values.scale = 0.8, n = 8))

We are in "plot" mode. Now we can plot the map by printing tm object:

tm

View mode

The same map in view mode:

ttm()
#>  tmap mode set to "view".
tm