【问题标题】:how to display a RasterBrick with tmap in the same way as raster::plotRGB如何以与 raster::plotRGB 相同的方式显示带有 tmap 的 RasterBrick
【发布时间】:2019-10-09 10:28:43
【问题描述】:

我非常喜欢 CARTO 的极简底图,但我无法将它们与我的首选地图工具 tmap 一起使用。我可能犯了一个愚蠢的错误,但我无法正确设置颜色。

library(tmap)
library(cartography)

data("NLD_prov")

# get the basemap

carto.raster <- getTiles(NLD_prov, type = "cartolight")

# This is the output I want
raster::plotRGB(carto.raster)

# This output looks bad
tm_shape(carto.raster) +
  tm_raster()

# I think I'm supposed to use tm_rgb() but that gives an error
tm_shape(carto.raster) +
  tm_rgb()

rgb(x[, 1], x[, 2], x[, 3], maxColorValue = 255) 中的错误: 颜色强度 NA,不在 0:255

【问题讨论】:

  • 您的代码不可重现...
  • 谢谢。我已经修好了。

标签: r r-raster tmap


【解决方案1】:

似乎tm_rgb 无法处理NA 值。你可以用raster::reclassify删除这些

library(raster)
library(tmap)
library(cartography)
data("NLD_prov")
carto.raster <- getTiles(NLD_prov, type = "cartolight")
r <- reclassify(carto.raster, cbind(NA, 255))
tm_shape(r) + tm_rgb()

要摆脱白色的 NA 边界,您可以使用 crop

e <- extent(11000, 288000, 305000, 625000)
x <- crop(r, e)
tm_shape(x) + tm_rgb()

【讨论】:

    猜你喜欢
    • 2020-07-21
    • 2019-06-22
    • 2017-10-05
    • 2019-01-22
    • 2012-08-16
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多