tmap_options | R Documentation |
Get or set global options for tmap. The behaviour of tmap_options
is similar to options
: all tmap options are retrieved when this function is called without arguments. When arguments are specified, the corresponding options are set, and the old values are silently returned as a list. The function tmap_options_reset
is used to reset all options back to the default values (also the style
is reset to "white"
). Differences with the default values can be shown with tmap_options_diff
. The function tmap_options_save
can be used to save the current options as a new style. See details below on how to create a new style.
tmap_options( ..., unit, limits, max.categories, max.raster, basemaps, basemaps.alpha, overlays, overlays.alpha, qtm.scalebar, qtm.minimap, qtm.mouse.coordinates, show.messages, show.warnings, output.format, output.size, output.dpi, output.dpi.animation, design.mode = NULL, check.and.fix ) tmap_options_diff() tmap_options_reset() tmap_options_save(style)
... |
options from |
unit |
this is the default value for the |
limits |
this option determines how many facets (small multiples) are allowed for per mode. It should be a vector of two numeric values named |
max.categories |
in case |
max.raster |
the maximum size of rasters, in terms of number of raster cells. It should be a vector of two numeric values named |
basemaps |
default basemaps. Basemaps are normally configured with |
basemaps.alpha |
default transparency (opacity) value for the basemaps. Can be a vector of values, one for each basemap. |
overlays |
default overlay tilemaps. Overlays tilemaps are shown as front layer (in contrast to basemaps, which are background layers), so they are only useful when they are semi-transparent. Like basemaps, a vector of tilemaps is expected, or |
overlays.alpha |
default transparency (opacity) value for the overlay maps. Can be a vector of values, one for each overlay map. |
qtm.scalebar |
should a scale bar be added to interactive maps created with |
qtm.minimap |
should a minimap be added to interactive maps created with |
qtm.mouse.coordinates |
should mouse coordinates (and zoom level) be shown in view mode with |
show.messages |
should messages be shown? |
show.warnings |
should warnings be shown? |
output.format |
The format of the static maps saved with |
output.size |
The size of the static maps saved with |
output.dpi |
The default number of dots per inch for |
output.dpi.animation |
The default number of dots per inch for |
design.mode |
Not used anymore; the design mode can now be set with |
check.and.fix |
Logical that determines whether shapes ( |
style |
style name |
The options can be divided into three parts: one part contains the arguments from tm_layout
, one part contains the arguments from tm_view
, and one part contains options that can only be set with tmap_options
. Observe that the options from tm_layout
and tm_view
can also be set with those functions. It is recommended to use tmap_options
when setting specific options during global session. However, options that are only relevant for a specific map can better be set with tm_layout
or tm_view
.
A new style can be created in two ways. The first approach is to use the function tmap_options_save
, which takes a snapshot of the current tmap options. E.g., tmap_options_save("my_style")
will save the current tmap options as a style called "my_style"
. See the examples in which a style called "red"
is created. The second way to create a style is to create a list with tmap options and with a attribute called style. This approach is illustrated in the last example, in which a style called "black"
is created.
The newly created style, say "my_style"
, will be accessible globally via tmap_style("my_style")
and + tm_style("my_style")
until the R session is restarted or tmap
is reloaded. In order to save the style for future use or sharing, obtain the option list as follows: my_style <- tmap_options()
and save the object my_style
in the usual way. Next time, the style can be loaded simply by running tmap_options(my_style)
, which corresponds to the second way to create a style (see the paragraph above).
tm_layout
, tm_view
, and tmap_style
# load data data(World) # get current options str(tmap_options()) # get current style tmap_style() # plot map (with default options) tm_shape(World) + tm_polygons("HPI") # change style to cobalt tmap_style("cobalt") # observe the changed options tmap_options_diff() # plot the map again tm_shape(World) + tm_polygons("HPI") ############################## # define red style ############################## # change the background color tmap_options(bg.color = "red") # note that the current style is modified tmap_style() # observe the changed options tmap_options_diff() # save the current options as style "red" tmap_options_save("red") # plot the map again tm_shape(World) + tm_polygons("HPI") # the specified arguments of tm_layout and tm_view will override the options temporarily: tm_shape(World) + tm_polygons("HPI") + tm_layout(bg.color="purple") # when tm_style_ is called, it will override all options temporarily: tm_shape(World) + tm_polygons("HPI") + tm_layout(bg.color="purple") + tm_style("classic") # reset all options tmap_options_reset() # check style and options tmap_style() tmap_options_diff() ############################## # define black style ############################## # create style list with style attribute black_style <- structure( list( bg.color = "black", aes.color = c(fill = "grey40", borders = "grey40", symbols = "grey80", dots = "grey80", lines = "white", text = "white", na = "grey30", null = "grey15"), aes.palette = list(seq = "plasma", div = "PiYG", cat = "Dark2"), attr.color = "white", panel.label.color = "white", panel.label.bg.color = "grey40", main.title.color = "white" ), style = "black" ) # assign the style tmap_options(black_style) # observe that "black" is a new style tmap_style() # plot the world map again, this time with the newly created black style tm_shape(World) + tm_polygons("HPI") # reset all options tmap_options_reset()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.