Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graceful handling for missing in add_circle_layer #30

Open
ews-grmunjal opened this issue Jul 30, 2024 · 1 comment
Open

graceful handling for missing in add_circle_layer #30

ews-grmunjal opened this issue Jul 30, 2024 · 1 comment

Comments

@ews-grmunjal
Copy link

ews-grmunjal commented Jul 30, 2024

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
Copy link
Author

ews-grmunjal commented Jul 30, 2024

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'
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant