Add XY points to raster map generated by levelplot

前端 未结 2 1545
不知归路
不知归路 2021-02-08 18:26

I have raster maps which are generated using the raster package in R. These raster layers can be visualized using the rasterVis package\'s

2条回答
  •  不要未来只要你来
    2021-02-08 18:38

    layer is very convenient for this:

    library(raster)
    library(rasterVis)
    library(sp)
    
    s <- stack(replicate(2, raster(matrix(runif(100), 10))))
    xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)),
                    z1=runif(10), z2=runif(10))
    coordinates(xy) <- ~x+y
    
    levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) + 
      layer(sp.points(xy, pch=ifelse(xy$z1 < 0.5, 2, 3), cex=2, col=1), columns=1) +
      layer(sp.points(xy, pch=ifelse(xy$z2 < 0.5, 2, 3), cex=2, col=1), columns=2)
    

    Note that the columns argument to layer (rows also exists) specifies which panel(s) you want to add the layer to.

    enter image description here

提交回复
热议问题