Open ews-grmunjal opened 1 month ago
reproducible example:
library(mapgl) library(sf) library(dplyr)
nc <- st_read(system.file('shape/nc.shp', package = 'sf'))
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' )
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' )
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