knitr::opts_chunk$set(fig.width = 8.83, message = FALSE)

Despite the possibility to quickly plot spatial data, mapview has a set of arguments for finer control of the visualization. Depending on the object class, these are:

All types

raster only

vector only


Here's a few examples of how selected arguments can be used:

Adjusting color, col.regions & at

Similar to the good old spplot, arguments col.regions and at can be used for finer control of the colouring

library(mapview)
library(raster)

pal = mapviewPalette("mapviewTopoColors")

kili_data <- system.file("extdata", "kiliNDVI.tif", package = "mapview")
kiliNDVI <- stack(kili_data)

mapview(kiliNDVI[[1]], col.regions = pal(100), at = seq(-0.2, 1, 0.2), legend = TRUE)


mapview(breweries, zcol = "founded", at = seq(1400, 2200, 200), legend = TRUE)

Changing map.types

To use a different background map, use argument map.types

mapview(breweries, map.types = c("Esri.WorldShadedRelief", "OpenStreetMap.DE"), color = "grey40")

Individual layer.name(s)

To individually label the layer names use argument layer.name

mapview(list(franconia, breweries),
        layer.name = c("Franconian districts", "Franconian breweries"))

Using burst

burst can be used to plot all layers of an object

mapview(breweries, burst = TRUE)


Note how all layers are shown by default. There is a hidden argument hide which can be used to hide all layers but the first.

mapview(breweries, burst = TRUE, hide = TRUE)


When burst used together with zcol, it will produce one layer for all unique values of zcol.

library(poorman)
library(sf)

breweries %>%
  st_intersection(franconia) %>%
  mapview(zcol = "district", burst = TRUE)


Note that for a column with many values there will likely not be enough space for the layers control - we are working on a solution for this issue.


Setting point size cex

For point data the circle size can be mapped to one of the attributes (features with NA values will be shown as dots)

mapview(breweries, cex = "number.of.types")

Adjusting opacity

Opacity of lines and fills (regions) can be adjusted using arguments alpha and alpha.regions

mapview(breweries, alpha = 0)


mapview(franconia, alpha.regions = 0.2, aplha = 1)

Multiple layers

In addition to easily style maps, mapview also makes it easy to add multiple layers to a (possibly laready existing) map. This can be done either by using + or by supplying a list of objects (or both).

library(plainview)

# mapview + object
mapview(list(franconia, breweries)) + poppendorf[[5]]


# mapview + mapview
mapview(franconia, zcol = "district") + mapview(breweries, zcol = "founded")


library(plainview)

# mapview w list of objects
mapview(list(breweries, franconia),
        zcol = list(NULL, "district"),
        legend = list(TRUE, FALSE),
        homebutton = list(FALSE, TRUE)) + poppendorf[[5]]


m1 = mapview(franconia, zcol = "district", col.regions = c("snow", "grey", "red"))
m1 + breweries

See chapter 3. mapview options for instructions on how to set some of these styling parameters permanently.



r-spatial/mapview documentation built on April 17, 2024, 6:46 p.m.