tmap (version 2.2)

tm_basemap: Draw a tile layer


Creates a tmap-element that draws a tile layer. This feature is only available in view mode. For plot mode, a tile image can be retrieved by read_osm. The function tm_basemap draws the tile layer as basemap (i.e. as bottom layer), whereas tm_tiles draws the tile layer as overlay layer (where the stacking order corresponds to the order in which this layer is called). Note that basemaps are shown by default (see details).


tm_basemap(server = NA, group = NA, alpha = NA)

tm_tiles(server, group = NA, alpha = 1)



name of the provider or an URL. The list of available providers can be obtained with leaflet::providers. See for a preview of those. When a URL is provided, it should be in template format, e.g. "http://{s}{z}/{x}/{y}.png". Use NULL in tm_basemap to disable the basemaps.


name of the group to which this layer belongs in view mode. Each group can be selected or deselected in the layer control item. Groups can either be specified as base or overlay groups in tm_view (arguments base.groups and overlay.groups). Tile layers generated with tm_basemap will be base groups whereas tile layers generated with tm_tiles will be overlay groups.




When tm_basemap is not specified, the default basemaps are shown, which can be configured by the basemaps arugument in tmap_options. By default (for style "white") three basemaps are drawn: c("Esri.WorldGrayCanvas", "OpenStreetMap", "Esri.WorldTopoMap"). To disable basemaps, add tm_basemap(NULL) to the plot, or set tmap_options(basemaps = NULL). Similarly, when tm_tiles is not specified, the overlay maps specified by the overlays argument in in tmap_options are shown as front layer. By default, this argument is set to NULL, so no overlay maps are shown by default. See examples.


Run this code
current.mode <- tmap_mode("view")

data(World, metro)

tm_basemap(leaflet::providers$Stamen.Watercolor) +
tm_shape(metro, bbox = "India") + tm_dots(col = "red", group = "Metropolitan areas") +
    "World_Light_Gray_Reference/MapServer/tile/{z}/{y}/{x}"), group = "Labels")

# Use tmap optinos to set the basemap and overlay map permanently during the R session:
opts <- tmap_options(basemaps = c(Canvas = "Esri.WorldGrayCanvas", Imagery = "Esri.WorldImagery"),
    overlays = c(Labels = paste0("",
	qtm(World, fill = "HPI", fill.palette = "RdYlGn")

# restore options

# restore current mode
# }

Run the code above in your browser using DataCamp Workspace