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
Note that there is big difference: in this "view"
mode
there are basemaps, and in "plot"
mode none. This is caused
by different default option.
Basemaps can be enabled or disabled via
tm_basemap()
:
tm + tm_basemap(NULL)
Mode specific options
Mode specific layout options can be set via tm_plot()
and tm_view()
. The number of options in
tm_plot()
is limited to just one, because it uses all
general purpose options. In contrast, tm_view()
contains
more options, e.g. there to position the control box and what the
default zoom level is:
For a more detailed description of options, see vignette about options.
Other modes
As of version 4, tmap can be extended with other modes. See (vignette about extensions).
library(tmap.deckgl)
tmap_mode("deck")
tm
The proof-of-concept package tmap.deckgl
only features
the map layer function tm_polygons()
(so the bubbles are
not working yet).