r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
868 stars 121 forks source link

tm_facets: `drop.units = FALSE` clashes with `drop.NA.facets=TRUE`: Column 'vneutral' does not exist to #932

Closed MatthieuStigler closed 2 months ago

MatthieuStigler commented 2 months ago

When running tm_facets() with both drop.units = FALSE and drop.NA.facets=TRUE, I get an error message:

Error in legs_aes$legend[[1]] : subscript out of bounds In addition: Warning message: In set(x, j = name, value = value) : Column 'vneutral' does not exist to remove

it seems that there is a conflict in these two options?

library(tmap)
#> 
#> Attaching package: 'tmap'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers

# Load the World dataset
data(World)

World2 <- World
World2$continent <- ifelse(sample(c(TRUE, FALSE), nrow(World2), TRUE), 
                           NA_character_, 
                           as.character(World$continent))

tm_shape(World2) +
  tm_borders() +
  tm_fill("pop_est") +
  tm_facets(by = "continent", drop.units = FALSE, drop.NA.facets=TRUE)
#> Warning in set(x, j = name, value = value): Column 'vneutral' does not exist to
#> remove
#> Error in legs_aes$legend[[1]]: subscript out of bounds

Created on 2024-09-03 with reprex v2.1.1

mtennekes commented 2 months ago

Thx! Was a hard one to debug but succeeded :-)