Skip to content

Instantly share code, notes, and snippets.

@ryanscharf
Last active July 24, 2024 20:42
Show Gist options
  • Save ryanscharf/ad6c262f52770a1c2ddc70fa4e56dee4 to your computer and use it in GitHub Desktop.
Save ryanscharf/ad6c262f52770a1c2ddc70fa4e56dee4 to your computer and use it in GitHub Desktop.
library(mapgl)
library(sf)
library(dplyr)
magma_pal <- viridisLite::magma(6)
magma_substr_pal <- substr(magma_pal, 1, 7)
nc <- st_read(system.file('shape/nc.shp', package = 'sf'))
nc <- nc %>% mutate(zz = sample(letters[1:6], nrow(.), replace = T))
# magma doesn't work
mapboxgl() %>%
fit_bounds(nc, animate = F) %>%
add_fill_layer(
id = 'GC Zones',
source = nc,
fill_color = match_expr(
column = 'zz',
values = unique(nc$zz),
stops = magma_pal
)
) %>%
add_legend(
'GC Zones',
values = unique(nc$zz),
colors = magma_pal,
type = 'categorical'
)
# dropping last FFs makes it work though
mapboxgl() %>%
fit_bounds(nc, animate = F) %>%
add_fill_layer(
id = 'GC Zones',
source = nc,
fill_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