mapgl icon indicating copy to clipboard operation
mapgl copied to clipboard

graceful handling for missing in add_circle_layer

Open ews-grmunjal opened this issue 1 year ago • 1 comments

if one of the values in the column is NA... no circles are rendered

good behaviour could be to have a na.rm type argument, if TRUE, dont render NA circles, if FALSE, NAs can be rendered as a separate category

ews-grmunjal avatar Jul 30 '24 12:07 ews-grmunjal

reproducible example:

library(mapgl) library(sf) library(dplyr)

nc <- st_read(system.file('shape/nc.shp', package = 'sf'))

WORKS

numcolors <- 6 nc <- nc %>% mutate(zz = sample(letters[1:numcolors], nrow(.), replace = T)) magma_pal <- viridisLite::magma(numcolors) magma_substr_pal <- substr(magma_pal, 1, 7)

mapboxgl() %>% fit_bounds(nc, animate = F) %>% add_circle_layer( id = 'GC Zones', source = nc, circle_color = match_expr( column = 'zz', values = unique(nc$zz), stops = magma_substr_pal ) ) %>% add_legend( 'GC Zones', values = unique(nc$zz), colors = magma_substr_pal, type = 'categorical' )

DOES NOT WORK

nc$zz[1] <- NA numcolors <- 7 magma_pal <- viridisLite::magma(numcolors) magma_substr_pal <- substr(magma_pal, 1, 7)

mapboxgl() %>% fit_bounds(nc, animate = F) %>% add_circle_layer( id = 'GC Zones', source = nc, circle_color = match_expr( column = 'zz', values = unique(nc$zz), stops = magma_substr_pal ) ) %>% add_legend( 'GC Zones', values = unique(nc$zz), colors = magma_substr_pal, type = 'categorical' )

ews-grmunjal avatar Jul 30 '24 12:07 ews-grmunjal