Learn R Programming

spatsurv (version 0.9-11)

spplot1: spplot1 function

Description

A function to provide spplot-like plotting capability but NOT using trellis graphics. This function also acts as an interface for fast plotting of SpatialPolygonsDataFrame or SpatialPixelsDataFrame objects using leaflet HTML plotting capabilities to get zoomable plots with real-world context: transformation to the correct projection is done automatically.

Usage

spplot1(x, what, palette = brewer.pal(5, "Oranges"), breaks = NULL,
  legpos = "topleft", fun = identity, include.lowest = TRUE, bty = "n",
  bg = NULL, printlegend = TRUE, bw = FALSE, useLeaflet = FALSE,
  urltemplate = urlTemplate("Stamen_Toner"), fillOpacity = 0.5,
  legendOpacity = 0.5, OSMbg = NULL, leafletLegend = TRUE, ...)

Arguments

x
a SpatialPolgonsDataFrame or a SpatialPointsDataFrame
what
the name of the variable to plot
palette
the palette, can either be a vector of names of colours, or a vector of colours produced for example by the brewer.pal function.
breaks
optional breaks for the legend, a vector of length 1 + length(palette)
legpos
the position of the legend, options are 'topleft', 'topright', 'bottomleft', 'bottomright'
fun
an optional function of the data to plot, default is the identity function
include.lowest
see ?cut
bty
see ?legend
bg
see ?legend
printlegend
logical: print the legend?
bw
Logical. Plot in black/white/greyscale? Default is to produce a colour plot. Useful for producing plots for journals that do not accept colour plots.
useLeaflet
whether to use leaflet to produce a zoomable map this requires the leaflet package, available by issuing the command "devtools::install_github('rstudio/leaflet')"
urltemplate
template for leaflet map background, default is urlTemplate('Stamen-Toner'), but any valid web address for leaflet templates will work here. See ?urlTemplate.
fillOpacity
see ?addPolygons
legendOpacity
see opacity argument in function addLegend
OSMbg
optional OpenStreetMap background to add to plot, obtain this using the function getBackground
leafletLegend
logical, display the leaflet legend?
...
other arguments to be passed to plot

Value

  • either produces a plot or if useLeaflet is TRUE, returns a leaflet map widget to which further layers can be added

Details

See http://leaflet-extras.github.io/leaflet-providers/preview/ for examples of leaflet templates.

Instructions on installing the leaflet R package are available from https://rstudio.github.io/leaflet/

See Also

urlTemplate, getBackground, brewer.pal