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 a system environment variable. This can be done
by
- running
usethis::edit_r_environ()
which creates/opens a text file named.Renviron
in your user’s home folder - adding the line
MAPBOX_PUBLIC_TOKEN="abc123"
, where abc123 should be replaced by your API key obtained in step 1.
- running
Enable "mapbox"
mode
tmap_mode("mapbox")
#> ℹ tmap modes "plot" -> "view" -> "mapbox" -> "maplibre"; rotate with
#> `tmap::rtm()`; switch to "plot" with `tmap::ttm()`
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] "mapbox.standard" "mapbox.streets"
#> [3] "mapbox.outdoors" "mapbox.light"
#> [5] "mapbox.dark" "mapbox.satellite"
#> [7] "mapbox.satellite_streets" "mapbox.navigation_day"
#> [9] "navigation_night" "mapbox.standard_satellite"
#> [11] "ofm.liberty" "ofm.bright"
#> [13] "ofm.positron" "ofm.dark"
#> [15] "ofm.fiord"
tm_shape(metro) +
tm_dots(size = "pop2020", fill = "red")+
tm_basemap("streets")

tmap mapbox mode