0

I like CARTO's minimalist basemaps quite a lot, but I'm having trouble using them with with tmap, my preferred mapping tool. I'm probably making a stupid mistake, but I can't get the colors right.

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()

Error in rgb(x[, 1], x[, 2], x[, 3], maxColorValue = 255) : color intensity NA, not in 0:255

John J.
  • 1,450
  • 1
  • 13
  • 28

1 Answers1

1

It seems that tm_rgb cannot handle NA values. You can remove these with 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()

to get rid of the white NA boundaries, you can use crop

e <- extent(11000, 288000, 305000, 625000)
x <- crop(r, e)
tm_shape(x) + tm_rgb()
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63