(CC-BY-NC-SA)
This document was produced on So Jun 12 2016 using mapview version 1.1.0
mapview provides a few convenience functions for popup creation. These popups can be used with both mapview and leaflet.
This is the standard popup function used by mapview
library(mapview)
mapview(breweries91, zcol = "founded")
It also works with leaflet and can be controlled to only show selected columns of the attribute table
leaflet() %>%
addTiles() %>%
addCircleMarkers(data = breweries91, popup = popupTable(breweries91, zcol = c("brewery", "village", "founded")))
To include lattice or ggplot2 or htmlwidgets based graphs in our popups we can use ppopupGraph()
. We have three options to embed grpahs in popups:
type = "png"
for png rendering of graphstype = "svg"
for svg rendering of graphstype = "html"
for html rendering of graphs (use this option to render htmlwidgets based visualisations)library(sp)
library(lattice)
pnt <- data.frame(x = 174.764474, y = -36.877245)
coordinates(pnt) <- ~ x + y
proj4string(pnt) <- "+init=epsg:4326"
p2 <- levelplot(t(volcano), col.regions = terrain.colors(100))
mapview(pnt, popup = popupGraph(p2, width = 300, height = 300))
data(meuse)
coordinates(meuse) <- ~ x + y
proj4string(meuse) <- CRS("+init=epsg:28992")
## create plots with points colored according to feature id
p <- xyplot(copper ~ cadmium, data = meuse@data, col = "grey")
p <- mget(rep("p", length(meuse)))
clr <- rep("grey", length(meuse))
p <- lapply(1:length(p), function(i) {
clr[i] <- "red"
update(p[[i]], col = clr)
})
mapview(meuse, popup = popupGraph(p, type = "svg", width = 3, height = 2.5))