knitr::opts_chunk$set( collapse = TRUE, fig.width = 8, comment = "#>" )
library(tmap)
Mapview is an excellent R package for interactive maps. Although the packages have a lot in common, the focus is different:
tmap "view" (with tm_view(use_WebGL = FALSE)
) is similar to mapview "leaflet"
tmap "view" (with tm_view(use_WebGL = TRUE)
) is similar to mapview "leafgl"
tmap does not offer a mode using Mapbox yet.
This is the default output of mapview
:
library(mapview) mapview(World)
This is the default output of tmap
:
tmap_mode("view") qtm(World) # qtm stands for 'quick thematic map'
mapview(World, zcol = "HPI")
tm_shape(World) + tm_polygons(fill = "HPI")
We can use tmap
to match the style of mapview
:
tm_shape(World) + tm_polygons( fill = "HPI", fill_alpha = 0.6, col_alpha = 0.9, fill.legend = tm_legend( title = "World - HPI", position = c("right", "top"), fill_alpha = 1), fill.scale = tm_scale_continuous(values = "viridis", n = 7, value.na = "#BEBEBE") ) + tm_basemap(c("CartoDB.Positron", "CartoDB.DarkMatter", "OpenStreetMap", "Esri.WorldImagery", "OpenTopoMap"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.