tmap is a R package for visualizing spatial data. This package, tmap.mapgl is an extension which features two new modes: "mapbox"
and "maplibre"
.
Installation
This package is in development so the development version of both tmap and tmap.mapgl are required.
tmap
# install.packages("remotes")
remotes::install_github("r-tmap/tmap")
# install.packages("pak")
pak::pak("r-tmap/tmap")
# Or from r-universe
install.packages("tmap", repos = c("https://r-tmap.r-universe.dev", "https://cloud.r-project.org"))
For Linux and macOS users who are new to working with spatial data in R, this may fail since additional (non-R) libraries are required (which are automatically installed for Windows users).
tmap.mapgl
# install.packages("remotes")
remotes::install_github("r-tmap/tmap.mapgl")
# install.packages("pak")
pak::pak("r-tmap/tmap.mapgl")
# Or from r-universe
install.packages("tmap.mapgl", repos = c("https://r-tmap.r-universe.dev", "https://cloud.r-project.org"))
For "mapbox"
an API key is required, which is free for personal use.
mapbox 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
Example
mapbox
library(tmap)
library(tmap.mapgl)
tmap_mode("mapbox")
tm_shape(World) +
tm_polygons("well_being",
fill.scale = tm_scale_continuous(values = "pu_gn"))

maplibre
tmap_mode("maplibre")
tm_shape(World) +
tm_polygons("well_being",
fill.scale = tm_scale_continuous(values = "pu_gn"))
