【发布时间】:2015-01-20 04:42:21
【问题描述】:
我正在尝试将点添加到使用 spplot() 函数绘制的图中。 我已经阅读了这个链接,但我还没有解决。
Overplotting two SpatialPolygonsDataFrames with spplot
plotting SpatialPointsDataFrame over a SpatialPolygonsDataFrame
http://www.r-bloggers.com/label-placement-with-spplot-and-lattice/
我将克里金法的结果存储在名为“k.o”的变量中,我想用克里金法获得的预测创建一张地图,并添加采取措施的点。 这是我的代码:
stations<-list('sp.points', zone, cex= 1, pch=19, col='black')
prediction_plot<-spplot(k.o["var1.pred"], col.regions=terrain.colors(20), cuts=19, auto.key=list(draw=TRUE),
asp='iso', colorkey=TRUE, main='Mean temperature prediction: january', sub='Lombardy',
scales=list(draw=TRUE), sp.layout=list(stations))
print(prediction_plot)
使用此代码,编译器不会给我任何错误,但我没有看到过度绘制的点(即我只看到克里金预测)。
我也尝试了 points(),但没有结果(但我不确定是否可以将 points() 与 spplot() 一起使用):
prediction_plot<-spplot(k.o["var1.pred"], col.regions=terrain.colors(20), cuts=19, auto.key=list(draw=TRUE),
asp='iso', colorkey=TRUE, main='Mean temperature prediction: january', sub='Lombardy',
scales=list(draw=TRUE))
points(zone$long, zone$lat, type='p', cex=0.5, col=2)
print(prediction_plot)
抱歉,我忘记了:'zone' 属于正式类 SpatialPointsDataFrame。
希望这个问题足够清楚,
提前致谢
编辑:我认为它是 rstudio,它在点上绘制克里格图,所以我尝试使用 sp.layout 的“第一”选项。
stations<-list('sp.points', zone, cex= 0.5, pch=19, col='black')
prediction_plot<-spplot(k.o['var1.pred'], col.regions=terrain.colors(20), cuts=19, auto.key=list(draw=TRUE),
asp='iso', colorkey=TRUE,
scales=list(draw=TRUE), sp.layout=list(stations, first=FALSE))
print(prediction_plot)
现在它为我绘制了点,但不是克里格预测,并且在绘图上,更进一步的点,它会打印一条错误消息,上面写着:“使用数据包 1 时出错。$ 运算符对原子向量无效”。 我搜了一下发现,为了避免这样的错误,需要用[]代替$,但是我已经在用了,用k.o['var1.pred']...
有什么建议吗?谢谢!
【问题讨论】:
-
有趣的问题。您的克里金法预测是否在网格上?如果是,您是否尝试过
gridded(k.o)=TRUE?
标签: r