我想在R中映射栅格和矢量数据

数据

class(Africa)# SpatialPolygonsDataFrame
class(Rift)#SpatialLinesDataFrame
class(Data.SP)#SpatialPointsDataFrame
class(An_Precip_subTest)#RasterLayer`

代码我正在尝试运行

tm_shape(Africa) + 
tm_raster(An_Precip_subTest)+
tm_shape(Data.SP) +
tm_dots(col="CS", auto.palette.mapping = FALSE, palette="-RdYlBu",
    breaks=Spectrum, title="Ventral Centroid Size", size=0.3)+
tm_shape(Rift) + tm_lines(col = "black") +
tm_legend(legend.outside=TRUE)

我收到此错误消息错误:非洲由多边形组成,因此它无法接受tm_raster .

我简单地在tmap之后模拟了我的代码(https://cran.r-project.org/web/packages/tmap/vignettes/tmap-nutshell.html

tm_shape(land) + 
tm_raster("trees", breaks=seq(0, 100, by=20), legend.show = FALSE) +
tm_shape(Europe, is.master = TRUE) +
tm_borders() +
tm_shape(rivers) +
tm_lines(lwd="strokelwd", scale=5, legend.lwd.show = FALSE) +
tm_shape(metro) +
tm_bubbles("pop2010", "red", border.col = "black", border.lwd=1, 
    size.lim = c(0, 11e6), sizes.legend = c(1e6, 2e6, 4e6, 6e6, 10e6), 
    title.size="Metropolitan Population") +
tm_text("name", size="pop2010", scale=1, root=4, size.lowerbound = .6, 
    bg.color="white", bg.alpha = .75, 
    auto.placement = 1, legend.size.show = FALSE) + 
tm_format_Europe() +
tm_style_natural()

他们只是在一个形状文件后放入一个光栅文件,一切正常 . 我不明白我的代码是如何不同和不正确的 . 我用这个例子(https://gis.stackexchange.com/questions/61243/clipping-a-raster-in-r)制作我的光栅文件我想知道其他人是否在重新创建这个例子时遇到了麻烦

如何将栅格和矢量数据一起映射?我正在尝试新的包,将数据转换为不同的格式等任何帮助表示赞赏 .