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).

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

This can be changed. The options are:

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

See previews

tm_shape(metro) +
    tm_bubbles(size = "pop2020") +
    tm_basemap("Esri.OceanBasemap")

View mode

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")`.
#> 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)