tmap 与 plotRGB
tmap vs plotRGB
我试图让使用 tmap::tm_raster 的颜色与使用 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 使 tmap_raster 看起来像 plotRGB 图像的任何想法?
谢谢,西蒙
我提出了一种可能不是最优雅的解决方案,但它获得的结果与您发布的解决方案非常相似。由于 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)
我试图让使用 tmap::tm_raster 的颜色与使用 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 使 tmap_raster 看起来像 plotRGB 图像的任何想法?
谢谢,西蒙
我提出了一种可能不是最优雅的解决方案,但它获得的结果与您发布的解决方案非常相似。由于 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)