Closed Robinlovelace closed 5 months ago
Cannot reproduce on my local version of tmap and I think the below reprex is the desired result. Can you reproduce Martijn/anyone?
# first intro plot -----------------------------------------------------------
library(terra)
#> terra 1.7.71
library(sf)
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
library(tmap)
#>
#> Attaching package: 'tmap'
#> The following object is masked from 'package:datasets':
#>
#> rivers
library(spData)
set.seed(2021-09-09)
small_ras = rast(matrix(1:16, 4, 4, byrow = TRUE))
crs(small_ras) = "EPSG:4326"
polys = st_as_sf(as.polygons(small_ras, na.rm = FALSE))
polys$lyr.1 = as.character(polys$lyr.1)
polys$vals = sample.int(100, 16)
polys$vals[c(7, 9)] = "NA"
suppressWarnings({polys$valsn = as.numeric(polys$vals)})
tm1 = tm_shape(polys) +
tm_borders(col = "black") +
tm_text(text = "lyr.1") +
tm_title("A. Cell IDs") +
tm_layout(frame = FALSE)
tm2 = tm_shape(polys) +
tm_borders(col = "black") +
tm_text(text = "vals") +
tm_title("B. Cell values") +
tm_layout(frame = FALSE)
tm3 = tm_shape(polys) +
tm_fill(fill = "valsn",
fill.scale = tm_scale(values = "RdBu", value.na = "white"),
fill.legend = tm_legend(show = FALSE)) +
tm_title("C. Colored values") +
tm_layout(frame = FALSE)
tmap_arrange(tm1, tm2, tm3, nrow = 1)
#> [cols4all] color palettes: use palettes from the R package cols4all. Run 'cols4all::c4a_gui()' to explore them. The old palette name "RdBu" is named "rd_bu" (in long format "brewer.rd_bu")
Created on 2024-06-12 with reprex v2.1.0
@Robinlovelace -- I can reproduce this error. I think it was introduced to tmap in the last few days. @mtennekes could you take a look at it? Simplified reprex is:
library(spData)
library(sf)
library(terra)
library(tmap)
set.seed(2021-09-09)
small_ras = rast(matrix(1:16, 4, 4, byrow = TRUE))
crs(small_ras) = "EPSG:4326"
polys = st_as_sf(as.polygons(small_ras, na.rm = FALSE))
polys$lyr.1 = as.character(polys$lyr.1)
tm1 = tm_shape(polys) +
tm_borders(col = "black") +
tm_text(text = "lyr.1")
tm1
#> Error in !legs_aes$legend[[k]]$active: invalid argument type
Created on 2024-06-12 with reprex v2.1.0
Looks like a regression to me, good to know it can be reproduced locally @Nowosad, clearly a {tmap} version issue that has been picked up quick in this case.
Working now
The latest version of tmap seems to be causing an error message:
See https://github.com/geocompx/geocompr/actions/runs/9475795989/job/26107667743#step:4:786 for the log and below for the bit of code. Can you try to reproduce @mtennekes and suggest work-around or upstream fix?
Thanks, happy providers of an unofficial tmap test suite : )