Interactive Viewing of Spatial Objects in R

Methods to view spatial objects interactively.

Interactive viewing of spatial objects in R

The online manual for mapview can be found at


For CRAN release version of mapview use


To install the development version install the devtools package.

devtools::install_github("environmentalinformatics-marburg/mapview", ref = "develop")


mapview is an R package created to help researchers during their spatial data analysis workflow. It provides functions to very quickly and conveniently create interactive visualisations of spatial data.

mapview was created o fill the gap of quick (not presentation grade) interactive plotting to examine and visually investigate spatial data. So far, one had to either:

  • (sp)plot the data in R and then toggle back and forth between the static plots (I use RStudio) or
  • save the data to the disk and then open in QGIS or similar to interactively examine the results.

The main workhorse function is mapView() and is currently defined for:

  • raster *objects (Layer, Stack, Brick) and SpatialPixelsDataFrame
  • sp *objects (Points, Polygons, Lines and their DataFrame version)
  • satellite *objects

mapview is in large parts based on RStudios leaflet package, though in order to aid general spatial analysis workflow, we have added a few special functions.


For small to moderately sized spatial objects, a call to mapView() will return an object of class mapview. This class has 2 slots:

  • @object - a list of the objects that are displayed on the map. This means that this slot will contain the re-projected (and in the case of Raster objects possibly re-sampled) objects which enables tracing of the modifications that took place.
  • @map - the leaflet map. This is an S3 class object (see leaflet package documentation for details on the specifics).

NOTE: For big spatial objects, only the map widget is returned. The distinction between small/moderate and big is made with respect to the number of features. The thresholds are 20k features for points and 30k features for polygons and lines. These values can be adjusted by setting the respective options.

By default mapView() provides five base layers between which one can toggle:

  • CartoDB.Positron (the default active layer)
  • OpenStreetMap
  • Esri.WorldImagery
  • Thunderforest.Landscape
  • OpenTopoMap

A preview of possible leaflet layers to use with mapview can be found here

Furthermore, a mouse coordinates strip is displayed at the top of the map giving information about the current mouse position and zoom level. Additionally, if the installed leaflet version permits, a scale bar is provided and labels are shown when hovering over a feature.

Depending on the object and/or argument settings one or several layers are created (each with or without it’s own legend) that can also be toggled. Note that in order to render properly, all layers need to be re-projected to leaflet’s underlying web mercator projection

+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs

which in the case of large Raster* objects or Spatial objects with lots of features can be time consuming.




for a brief introduction how to use projected maps with mapview


Please file bug reports and feature requests at


new features:

  • garnishMap: function to add multiple decoration elements, such as leaflet::addLayersControl or addHomeButton to a map (mainly for internal use).
  • addHomeButton: add a zoom-to-layer button to a map.
  • addLogo: add an image to a map.
  • plainview now shows CRS and dimension info.


  • na.color was not respected for Raster* and SpatialPiXelsDF.
  • removed lat and lon entries in popupTable for polygons as we now have mousecoordinates.
  • for raster objects the legend did not respect the intervals specified by 'at'.
  • mapview working again for objects with no projection (NA).
  • mapview for SPoints* with only one point did through an error #36.

new features:

  • addMouseCoordinates: add cursor position information to mapview or leaflet map. (thanks to Kent Russell).
  • if available from leaflet version, a scalebar is added to the map.
  • latticeView: view mapview or leaflet maps as small multiples and sync some, all or none (thanks to Kent Russell).
  • sync: synchronise two or more leaflet maps (thanks to Kenton Russell).
  • mapshot: to save maps as html page or static image or both.
  • knitr integration (i.e. no need to call the @map slot anymore to render in knitr).
  • cubeView: view raster bricks or stacks hovmoeller style, use keys up & down, left & right, page up & page down to navigate through y, x, z dimensions, respectively.
  • labels: if zcol is set, mouseover will now show the repesctive values of zcol, if zcol is not set moseover shows feature ID. Only available if suitable leaflet package version is installed.
  • new popup functions popupTable, popupGraph and popupImage.
  • functions to turn coordinates into spatial lines or spatial polygons.
  • mapview objects now work natively on shiny applications (i.e. renderMapview and mapviewOutput now available).
  • "zcol = Var" in combination with burst = TRUE now plots one layer for each unique value of the variable supplied to zcol.


  • spplot method has been removed.
  • colors: viridis based colors now default if viridisLite package is available.
  • basemaps: new default basemap is "CartoDB.Positron" as colors of features are better visible on the grey background.
  • layer names now include the name of the object they originate from (e.g. "meuse lead" instead of "lead").


  • if attribute was of class "character" mapview did through an error if passed to zcol.
  • user provided layer names were not respected when zcol was set. See also note on changes in default layer names.
  • Initial release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


2.0.1 by Tim Appelhans, 17 days ago

Report a bug at

Browse source code at

Authors: Tim Appelhans [cre, aut], Florian Detsch [aut], Christoph Reudenbach [aut], Stefan Woellauer [aut], Spaska Forteva [ctb], Thomas Nauss [ctb], Edzer Pebesma [ctb], Kenton Russell [ctb], Michael Sumner [ctb], Environmental Informatics Marburg [ctb]

Documentation:   PDF Manual  

Task views: Analysis of Spatial Data

GPL (>= 3) | file LICENSE license

Imports sp, raster, satellite, scales, brew, htmlwidgets, htmltools, png, Rcpp, lattice, gdalUtils, data.table, webshot, viridisLite, sf, base64enc

Depends on leaflet, methods

Suggests knitr, rmarkdown, dplyr

Linking to Rcpp

System requirements: GNU make

Imported by tmap.

See at CRAN