Skip to contents

Basemaps

By default, basemaps are only shown in "view" mode, so not in "plot" mode. Basemaps can be enabled or disabled via tm_basemap().

Plot mode

To enable a basemap in plot mode, the package maptiles is required. When specified without arguments, the default basemap server is “Esri.WorldGrayCanvas” (run tmap_options("basemap.server") to see this option). This can be changed, e.g. "OpenTopoMap".

tm_shape(metro) +
    tm_bubbles(size = "pop2020") +
    tm_basemap("OpenTopoMap")

The options are:

names(maptiles::get_providers())
#>  [1] "OpenStreetMap"                  "OpenStreetMap.DE"              
#>  [3] "OpenStreetMap.France"           "OpenStreetMap.HOT"             
#>  [5] "OpenTopoMap"                    "Stadia.AlidadeSmooth"          
#>  [7] "Stadia.AlidadeSmoothDark"       "Stadia.OSMBright"              
#>  [9] "Stadia.Outdoors"                "Stadia.StamenToner"            
#> [11] "Stadia.StamenTonerBackground"   "Stadia.StamenTonerLines"       
#> [13] "Stadia.StamenTonerLabels"       "Stadia.StamenTonerLite"        
#> [15] "Stadia.StamenWatercolor"        "Stadia.StamenTerrain"          
#> [17] "Stadia.StamenTerrainBackground" "Stadia.StamenTerrainLabels"    
#> [19] "Esri.WorldStreetMap"            "Esri.WorldTopoMap"             
#> [21] "Esri.WorldImagery"              "Esri.WorldTerrain"             
#> [23] "Esri.WorldShadedRelief"         "Esri.OceanBasemap"             
#> [25] "Esri.NatGeoWorldMap"            "Esri.WorldGrayCanvas"          
#> [27] "CartoDB.Positron"               "CartoDB.PositronNoLabels"      
#> [29] "CartoDB.PositronOnlyLabels"     "CartoDB.DarkMatter"            
#> [31] "CartoDB.DarkMatterNoLabels"     "CartoDB.DarkMatterOnlyLabels"  
#> [33] "CartoDB.Voyager"                "CartoDB.VoyagerNoLabels"       
#> [35] "CartoDB.VoyagerOnlyLabels"      "Thunderforest.OpenCycleMap"    
#> [37] "Thunderforest.Transport"        "Thunderforest.TransportDark"   
#> [39] "Thunderforest.SpinalMap"        "Thunderforest.Landscape"       
#> [41] "Thunderforest.Outdoors"         "Thunderforest.Pioneer"         
#> [43] "Thunderforest.MobileAtlas"      "Thunderforest.Neighbourhood"

See previews

tm_shape(metro) +
    tm_bubbles(size = "pop2020") +
    tm_basemap("CartoDB.PositronNoLabels")

Note: the Esri basemaps (also the default) do not render well issue

View mode

In view mode, there are even more options. There can be obtained via names(leaflet::providers).

tmap_mode("view")
#>  tmap mode set to "view".
tm_shape(metro) +
    tm_bubbles(size = "pop2020") +
    tm_basemap("Esri.OceanBasemap")

Disabling basemaps:

tmap_mode("view")
#>  tmap mode set to "view".
tm_shape(World) +
  tm_polygons(
    fill = "grey80", 
    col = "grey60") +
tm_shape(metro) +
    tm_bubbles(size = "pop2020") +
    tm_basemap(NULL)
#> [tip] Consider a suitable map projection, e.g. by adding `+ tm_crs("auto")`.
#> [view mode] WegGL does not work (yet) with projected map projections, so it has
#> been disabled.
#> [view mode] WegGL does not work (yet) with projected map projections, so it has
#> been disabled.
#> This message is displayed once per session.

Now it is also possible to use different map projections (see vignette):

tmap_mode("view")
#>  tmap mode set to "view".
tm_shape(World, crs = "+proj=robin") +
  tm_polygons(
    fill = "grey80", 
    col = "grey60") +
tm_shape(metro) +
    tm_bubbles(size = "pop2020") +
    tm_basemap(NULL)
#> [view mode] WegGL does not work (yet) with projected map projections, so it has
#> been disabled.
#> [view mode] WegGL does not work (yet) with projected map projections, so it has
#> been disabled.