在tmap中绘制山影

时间:2018-09-03 13:41:41

标签: r raster tmap

我想用hillshading绘制栅格,并用tmap添加图层。

library(raster)
alt = getData('alt', country='CHE')
slope = terrain(alt, opt='slope')
aspect = terrain(alt, opt='aspect')
hill = hillShade(slope, aspect, 40, 270)
plot(hill, col=grey(0:100/100), legend=FALSE, main='Switzerland')
plot(alt, col=rainbow(25, alpha=0.35), add=TRUE)

enter image description here

我想使用tmap覆盖道路等。如何进行这项工作?

library(tmap)
tm_shape(hill) + tm_raster() + tm_shape(alt) + tm_raster()

相同
tm_shape(alt) + tm_raster()

tm_shape(hill) + tm_raster()部分给出警告消息:

Variable "layer" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.

1 个答案:

答案 0 :(得分:1)

library(tmap)  
tm_shape(hill) +
 tm_raster(palette = gray(0:100 / 100), n = 100, legend.show = FALSE)  +
  tm_shape(alt) +
  tm_raster(alpha = 0.5, palette = terrain.colors(25),
            legend.show = FALSE)

感谢tmap github page上的Nowosad。