将XY点添加到由levelplot生成的栅格地图中 [英] Add XY points to raster map generated by levelplot
问题描述
我有raster
地图,这些地图是使用R中的raster
程序包生成的.可以使用rasterVis
程序包的levelplot
函数将这些栅格图层可视化:
I have raster
maps which are generated using the raster
package in R. These raster layers can be visualized using the rasterVis
package's levelplot
function:
levelplot(rasterstack, layout=c(1, 2),
col.regions=colorRampPalette(c('darkred', 'red3', 'orange2', 'orange',
'yellow', 'lightskyblue', 'steelblue3',
'royalblue3', 'darkblue')))
现在,我想将xy坐标定义的一些z值添加到水平图映射中.包含z值的数据框有4列.第1列和第2列2包含x& y坐标,第3列包含layout(1,1)中地图1的z值,而layout(1,2)中列4的z值.
Now, I would like to add some z values defined by xy cordinates to the levelplot map. The dataframe containing z values has 4 columns. Columns 1 & 2 contain x & y coordinates, column 3 contains z values for map 1 in layout(1, 1) and column 4 for layout(1, 2).
每张地图的点数应相加,如果z< 0.05,pch=2
,如果z> 0.05,pch=3
.
The points per map should be added such that if z < 0.05, pch=2
and if z > 0.05, pch=3
.
我已经在网上搜索并找到了Ripley的解决方案,但在我的情况下它不起作用:
I have searched the web and found a solution by Ripley but it does not work in my case:
levelplot(rcp852, xlab = "", ylab = "",
panel = function(x, y, subscripts, ...) {
panel.levelplot(x, y, subscripts, ...)
panel.xyplot(topo$x,topo$y, cex = 0.5, col = 1)
}
)
我尝试了许多其他选择,但是这些点与通过levelplot
生成的地图不对齐.
I tried many other options but the points do not align with the map generated via levelplot
.
推荐答案
layer
对此非常方便:
s <- stack(replicate(2, raster(matrix(runif(100), 10))))
xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)),
z1=runif(10), z2=runif(10))
levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) +
layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1), columns=1) +
layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1), columns=2)
请注意,layer
的columns
参数(也存在rows
)指定要将图层添加到的面板.
Note that the columns
argument to layer
(rows
also exists) specifies which panel(s) you want to add the layer to.
这篇关于将XY点添加到由levelplot生成的栅格地图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!