For "mapbox"
an API key is required, which is free for
personal use.
Getting and using the API key
- Go to Mapbox Access Tokens and follow the instructions
- Set the API key as system environment variable. This can be done by
- running
usethis::edit_r_environ()
which creates/opens a text file named.Renviron
in your users home folder - adding the line
MAPBOX_PUBLIC_TOKEN="abc123"
, where abc123 should be replaced by your in step 1 obtained API key.
- running
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
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