tmap_mode {tmap} | R Documentation |
Set tmap mode to static plotting or interactive viewing
Description
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 = c("plot", "view"))
ttm()
ttmp()
Arguments
mode |
one of
|
Value
the mode before changing
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
vignette("tmap-getstarted")
, tmap_last
to show the last map, tm_view
for viewing options, and tmap_leaflet
for obtaining a leaflet widget, and tmap_options
for tmap options.
Examples
# world choropleth/bubble map of the world
data(World, metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100
map1 <- tm_shape(World) +
tm_polygons("income_grp", palette="-Blues", contrast=.7, id="name", title="Income group") +
tm_shape(metro) +
tm_bubbles("pop2010", col = "growth",
border.col = "black", border.alpha = .5,
style="fixed", breaks=c(-Inf, seq(0, 6, by=2), Inf),
palette="-RdYlBu", contrast=1,
title.size="Metro population",
title.col="Growth rate (%)", id="name",
popup.vars = c("pop2010", "pop2020", "growth")) +
tm_layout(legend.bg.color = "grey90", legend.bg.alpha=.5, legend.frame=TRUE)
# initial mode: "plot"
current.mode <- tmap_mode("plot")
# plot map
map1
# switch to other mode: "view"
ttm()
# view map
map1
## Not run:
# choropleth of the Dutch population in interactive mode:
require(tmaptools)
data(NLD_muni, NLD_prov)
NLD_muni$pop_dens <- calc_densities(NLD_muni, var = "population")
tm_shape(NLD_muni) +
tm_fill(col="pop_dens",
style="kmeans",
title = "Population (per km^2)", id = "name") +
tm_borders("grey25", alpha=.5) +
tm_shape(NLD_prov) +
tm_borders("grey40", lwd=2)
## End(Not run)
# restore current mode
tmap_mode(current.mode)