【发布时间】:2022-01-01 22:21:17
【问题描述】:
我遇到了麻烦。在 tmap 中使用相同的 CRS 绘制 SpatialPixelDataframe 和 SpatialPolygonDataframe 时,我无法识别问题。
spatialpixels 对象可以在保存为 RDS 的here 中找到,多边形 shapefile here 已压缩。
这是我对基本函数的尝试:
library(sf)
library(sp)
ireland <- st_read("Counties.shp")
sp_pred <- readRDS("sppred_range100_sd2.RDS")
#transform polygons into the pixels CRS
ireland_proj <- st_transform(ireland, sp_pred@proj4string)
#turn into sp object
ireland_sp <- as_Spatial(ireland_proj)
#plot with base functions
plot(sp_pred['mean'])
plot(ireland_sp, add = T)
这是我对tmap的尝试
library(tmap)
tm_shape(sp_pred) +
tm_raster("mean", palette = terrain.colors(10)) +
tm_shape(ireland_sp) +
tm_borders("black", lwd = .5) +
tm_legend(show = FALSE)
这太简单了,我看不出哪里出了问题,但我也看不出tmap的工作方式有什么错误!
【问题讨论】:
-
我自己无法找到错误,但这看起来很可能是投影问题。 NB。您还在
tm_shape中使用 sp 类 SpatialPolygonsDataFrame 和 SpatialPixelDataFrame,虽然不鼓励使用这些类。请参阅?tm_shape:“shp – 形状对象,它是来自 'sf' 或 'stars' 包定义的类的对象。也支持来自包 'sp' 和 'raster' 的对象,但不鼓励。”