Skip to contents

Set tmap mode to static plotting or interactive viewing. The global option tmap.mode determines the whether thematic maps are plot in the graphics device, or shown as an interactive leaflet map (see also tmap_options(). The function tmap_mode() is a wrapper to set this global option. The convenient function ttm(), which stands for toggle thematic map, is a toggle switch between the two modes. The function ttmp() stands for toggle thematic map and print last map: it does the same as ttm() followed by tmap_last(); in order words, it shows the last map in the other mode. It is recommended to use tmap_mode() in scripts and ttm()/ttmp() in the console.

Usage

tmap_mode(mode = NULL)

ttm()

ttmp()

Arguments

mode

One of "plot" or "view". See Details for more info.

Value

The previous tmap mode before switching.

mode = "plot"

Thematic maps are shown in the graphics device. This is the default mode, and supports all tmap's features, such as small multiples (see tm_facets()) and extensive layout settings (see tm_layout()). It is recommended to use tmap_save() for saving static maps.

mode = "view"

Thematic maps are viewed interactively in the web browser or RStudio's Viewer pane. Maps are fully interactive with tiles from OpenStreetMap or other map providers (see tm_tiles()). See also tm_view() for options related to the "view" mode. This mode generates a leaflet::leaflet() widget, which can also be directly obtained with tmap_leaflet(). With R Markdown, it is possible to publish it to an HTML page.

However, there are a couple of constraints in comparison to "plot":

  • The map is always projected according to the Web Mercator projection. Although this projection is the de facto standard for interactive web-based mapping, it lacks the equal-area property, which is important for many thematic maps, especially choropleths (see examples from tm_shape()).

  • Small multiples are not supported

  • The legend cannot be made for aesthetics regarding size, which are symbol size and line width.

  • Text labels are not supported (yet)

  • The layout options set with tm_layout()) regarding map format are not used. However, the styling options still apply.

References

Tennekes, M., 2018, tmap: Thematic Maps in R, Journal of Statistical Software, 84(6), 1-39, doi:10.18637/jss.v084.i06

See also

Examples

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

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

tm_shape(World) + tm_polygons("HPI")


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

tm_shape(World) + tm_polygons("HPI")

ttm()
#>  tmap mode set to "plot".

tm_shape(World) + tm_polygons("HPI")