Maybe a little late, but here is the solution. The addPopups() function in library(leaflet) seems to be able to handle .svg files. So you can just save your plot with svg() and then read it again using readLines() . Here's a reproducible example using library(mapview) :
library(lattice) library(mapview) library(sp) data(meuse) coordinates(meuse) <- ~x+y proj4string(meuse) <- CRS("+init=epsg:28992") clr <- rep("grey", length(meuse)) fldr <- tempfile() dir.create(fldr) pop <- lapply(seq(length(meuse)), function(i) { clr[i] <- "red" p <- xyplot(meuse$cadmium ~ meuse$copper, col = clr, pch = 20, alpha = 0.7) svg(filename = paste(fldr, "test.svg", sep = "/"), width = 250 * 0.01334, height = 250 * 0.01334) print(p) dev.off() tst <- paste(readLines(paste(fldr, "test.svg", sep = "/")), collapse = "") return(tst) }) mapview(meuse, popup = pop, cex = "cadmium")
You will see that each popup is a scatter chart. As for the leaflet example, consider this:
content <- pop[[1]] leaflet() %>% addTiles() %>% addPopups(-122.327298, 47.597131, content, options = popupOptions(closeButton = FALSE) )
If you want the graph to be interactive, you could take a look at the library(gridSVG) , which can create interactive svg graphs, for example. lattice or ggplot2 .
UPDATE:
library(mapview) now designated functionality for this:
popupGraph : embed lattice graphics, ggplot2 or interactive hatmlwidgets .popupImage : embed local or remote (web images)
Currently, this is only available in the mapview development version , which can be installed using
devtools::install_github("environmentalinformatics-marburg/mapview", ref = "develop"