Tmap: The view mode drops a color palette for raster data

Created on 26 Apr 2020  路  4Comments  路  Source: mtennekes/tmap

library(tmap)
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.7.1, GDAL 2.3.2, PROJ 5.2.0
library(raster)
#> Loading required package: sp
# data download -----------------------------------------------------------
tf = tempfile(fileext = ".zip")
td = tempdir()
download.file("https://github.com/r-spatial/stars/files/4345255/lanform-example.zip", tf)
unzip(tf, exdir = td)
lf_path = paste0(td, "/lanform.tif")

# data read ---------------------------------------------------------------
# colors are here
lf = read_stars(lf_path)

# colors are correct
tm_shape(lf) +
  tm_raster()
#> Warning: Duplicated levels found. They have been omitted


# colors are not correct
tmap_mode("view")
#> tmap mode set to interactive viewing
tm_shape(lf) +
  tm_raster()
#> Warning: Duplicated levels found. They have been omitted

Created on 2020-04-26 by the reprex package (v0.3.0)

bug

Most helpful comment

@edzer you probably also need to update tmaptools: remotes::install_github("mtennekes/tmaptools")

All 4 comments

Fixed now.

@Nowosad Do you have the latest github version? I ask because the colors of the first map are also incorrect. They do look correct over here. The saturated green should be 5, and 17 should be blue. (Sorry, to lazy to take a screenshot).

@edzer The "colors" attribute got lost after an st_warp. I have sf 0.9-2, so not sure if you already fixed this.

Thanks for asking @mtennekes - I usually work on a server with the latest dev version of tmap, and I found this issue there. However, I made the reprex on my local computer (which is going to be updated to Fedora 32 and R4 this week)..

Now this example works perfectly.

I'm looking at this, but with tmap installed from github I see

> tm_shape(lf) +
+   tm_raster()
Error in bb(x = c(xmin = -1091676.0997804, ymin = -1182669.97103175, xmax = 1117098.54433339,  : 
  unused argument (asp.limit = 10)
> traceback()
5: do.call("bb", args)
4: process_shapes(shps, x[gm$shape.id], gm, data_by, allow.crop = FALSE, 
       interactive = interactive)
3: print_tmap(x = x, vp = vp, return.asp = return.asp, mode = mode, 
       show = show, knit = knit, options = options, ...)
2: print.tmap(x)
1: (function (x, ...) 
   UseMethod("print"))(x)

@edzer you probably also need to update tmaptools: remotes::install_github("mtennekes/tmaptools")

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Si-Chong picture Si-Chong  路  4Comments

prosoitos picture prosoitos  路  5Comments

hbermeo picture hbermeo  路  8Comments

dylanbeaudette picture dylanbeaudette  路  3Comments

zjslagle picture zjslagle  路  4Comments