有很好的示例如何在Plotting vector maps overlaid on top of a raster background in R或Overlay your raster layer on a background GM layer in R等栅格图层上叠加矢量/栅格地图。但合并后的图形中缺少传说。在示例rproblv
中有一个图例但migmaplv + rproblv
没有。
是否有一种简单的方法可以合并两个levelplot
或spplot
个对象并在结果中保留一个或两个图例?
来自Overlay your raster layer on a background GM layer in R
library(utils); library(colorRamps); library(rgdal);
library(raster); library(dismo); library(rasterVis)
download.file(
"https://dl.dropboxusercontent.com/u/3180464/rprob520.tif",
"rprob520.tif", method = "curl")
rprob <- raster("rprob520.tif")
rprobGM <- projectRaster(from = rprob, crs = CRS("+init=epsg:3857"))
migmap <- gmap(x = rprob, type = "hybrid", zoom = 5)
migmaplv <- levelplot(
migmap, maxpixels = ncell(migmap),
col.regions = migmap@legend@colortable,
at = 0:255, panel = panel.levelplot.raster, interpolate = TRUE,
colorkey = FALSE, margin = FALSE)
rproblv <- levelplot(
rprobGM, margin = FALSE, contour = TRUE,
par.settings = rasterTheme(region = matlab.like(n = 10)),
alpha.regions = 0.35, at = (0:10)/10,
main = "p(dep > 1kg/m2 per eruption event)")
print(migmaplv + rproblv)
答案 0 :(得分:4)
将as.layer
功能与under = TRUE
:
rproblv + as.layer(migmaplv, under = TRUE)