Skip to contents

For "mapbox" an API key is required, which is free for personal use.

Getting and using the API key

  1. Go to Mapbox Access Tokens and follow the instructions
  2. Set the API key as system environment variable. This can be done by
    1. running usethis::edit_r_environ() which creates/opens a text file named .Renviron in your users home folder
    2. adding the line MAPBOX_PUBLIC_TOKEN="abc123", where abc123 should be replaced by your in step 1 obtained API key.

Enable "mapbox" mode

tmap_mode("mapbox")
#>  tmap mode set to "mapbox".

Example

tm_shape(World) + 
  tm_polygons("well_being",
    fill.scale = tm_scale_continuous(values = "pu_gn"))
tmap mapbox mode
tmap mapbox mode

Basemaps

Mapbox offers several basemap providers, namely:

tmap_providers()
#>  [1] "standard"           "streets"            "outdoors"          
#>  [4] "light"              "dark"               "satellite"         
#>  [7] "satellite-streets"  "navigation-day"     "navigation-night"  
#> [10] "standard-satellite"
tm_shape(metro) + 
  tm_dots(size = "pop2020", fill = "red")+
tm_basemap("streets")
tmap mapbox mode
tmap mapbox mode