我试图让使用tmap::tm_raster的颜色与用光栅::plotRGB绘制的颜色相同。
我的数据集在这里https://drive.google.com/drive/folders/1a5gOJ2S6lf_5nWu2ViU-6TRfi_gTMqi-?usp=sharing
首先我上传我的数据:
library(raster)
DEM_grey <- raster::raster("DEM100GREY_clip.tif")然后我用tmap绘制它。
library(tmap)
tm_map::tm_shape(DEM_grey)+
tmap::tm_raster(palette = "-Greys")看起来就像这样

现在我用光栅来画它
library(raster)
raster::plotRGB(DEM_grey)我得到了我想要的灰色等级

对于如何让tmap_raster看起来像使用tmap的plotRGB图像,有什么想法吗?
谢谢,西蒙
发布于 2020-04-09 02:01:32
我提供了一个可能不是最优雅的解决方案,但它得到的结果与您发布的结果非常相似。当tm_raster将栅格值分类为离散类时,您可以手动分配断点以显示,例如,255个不同色调的灰色DEM。
library(tmap)
library(raster)
#Get the image min, max and the range divided by 255
#255 is the number of different tones of grey you will get in your plot
rast_min<-cellStats(DEM_grey,min)
rast_max<-cellStats(DEM_grey,max)
rast_step<-ceiling((rast_max-rast_min)/255)
tm_shape(DEM_grey)+
tm_raster(palette = "-Greys",
breaks = seq(rast_min,rast_max,rast_step),
#You can hide the legend using legend.show = F
legend.show = F) https://stackoverflow.com/questions/61111959
复制相似问题