Learn R Programming

tmap (version 1.6-1)

tm_view: Options for the interactive tmap viewer

Description

Set the options for the interactive tmap viewer. Some of these options can also be set with tm_layout, since they are style dependent (e.g., the choice of basemaps). The function tm_view overrides these options when specified.

Usage

tm_view(alpha = NA, colorNA = NULL, basemaps = NA, basemaps.alpha = NA, symbol.size.fixed = FALSE, dot.size.fixed = TRUE, set.bounds = FALSE, set.view = NA, set.zoom.limits = NA, legend.position = c("right", "top"), control.position = c("left", "top"), popup.all.data = NULL, bg.overlay = NULL, bg.overlay.alpha = NULL)

Arguments

alpha
transparency (opacity) parameter applied to whole map. By default, it is set to 0.7 if basemaps are used, and 1 otherwise.
colorNA
default color for missing values (that is, in case colorNA is unspecified in layer functions such as tm_fill). The default value of NULL means transparent. It overrides the na value of the aes.color in tm_layout.
basemaps
vector of one or more names of baselayer maps, or a logical value. See http://leaflet-extras.github.io/leaflet-providers/preview. Also supports URL's for tile servers, such as "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png". By default (NA), the choice of basemap(s) will be determined by the basemaps argument of tm_layout, which is style dependent. Use TRUE to select a large set of recommended basemaps. Use FALSE to omit basemap tiles. If a named vector is provided, the names are used in the layer control legend.
basemaps.alpha
transparency (opacity) value for the basemaps. Can be a vector of values, one for each basemap.
symbol.size.fixed
should symbol sizes be fixed while zooming?
dot.size.fixed
should dot sizes be fixed while zooming?
set.bounds
logical that determines whether maximum bounds are set, or a numeric vector of four values that specify the lng1, lat1, lng2, and lat2 coordinates (see setMaxBounds).
set.view
numeric vector or three that determines the view: lng, lat, and zoom (see setView).
set.zoom.limits
numeric vector of two that set the minimum and maximum zoom levels (see tileOptions).
legend.position
Character vector of two values, specifing the position of the legend. Use "left" or "right" for the first value and "top" or "bottom" for the second value. It overrides the value of legend.position of tm_layout, unless set to NA.
control.position
Character vector of two values, specifing the position of the layer control UI. Use "left" or "right" for the first value and "top" or "bottom" for the second value.
popup.all.data
not used anymore. As of version 1.6, the popups are specified by the argument popup.vars in the layer functions tm_fill, tm_symbols, and tm_lines.
bg.overlay
not used anymore as of version 1.7. Instead of an overlay, a background color is set, which is determined by bg.color of tm_layout, which is style dependent.
bg.overlay.alpha
not used anymore as of version 1.7. Instead of an overlay, a background color is set. The trade-off between background and basemaps can now be set by basemaps.alpha

See Also

tmap_mode and vignette("tmap-modes")

Examples

Run this code
# world choropleth/bubble map of the world
data(World, metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100

map1 <- 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_legend(outside=TRUE)

current.mode <- tmap_mode("plot")

# plot map
map1

# view map with default view options
tmap_mode("view")
map1

# view map with changed view options
map1 + tm_view(alpha = 1, basemaps = "Stamen.Watercolor")

# restore current mode
tmap_mode(current.mode)

Run the code above in your browser using DataLab