顶部栅格背景上的空间对象的图例

时间:2015-04-08 16:02:24

标签: r geospatial lattice raster r-raster

有很好的示例如何在Plotting vector maps overlaid on top of a raster background in ROverlay your raster layer on a background GM layer in R等栅格图层上叠加矢量/栅格地图。但合并后的图形中缺少传说。在示例rproblv中有一个图例但migmaplv + rproblv没有。

是否有一种简单的方法可以合并两个levelplotspplot个对象并在结果中保留一个或两个图例?

来自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)

enter image description here

1 个答案:

答案 0 :(得分:4)

as.layer功能与under = TRUE

一起使用
rproblv + as.layer(migmaplv, under = TRUE)