Skip to content

Instantly share code, notes, and snippets.

@PaulC91
Created January 21, 2020 23:23
Show Gist options
  • Save PaulC91/8e95071bbc6f4856e9713d886dd2927e to your computer and use it in GitHub Desktop.
Save PaulC91/8e95071bbc6f4856e9713d886dd2927e to your computer and use it in GitHub Desktop.
render place tile labels above polygons in R leaflet
library(leaflet)
world <- rnaturalearth::ne_countries(returnclass = "sf")
pal <- colorFactor("Dark2", levels = unique(world$continent))
leaflet(world) %>%
setView(10, 15, zoom = 3) %>%
addMapPane(name = "polygons", zIndex = 410) %>%
addMapPane(name = "maplabels", zIndex = 420) %>% # higher zIndex rendered on top
addProviderTiles("CartoDB.Positron") %>%
addProviderTiles("CartoDB.PositronOnlyLabels", options = leafletOptions(pane = "maplabels")) %>%
addPolygons(
fillColor = ~pal(continent),
weight = 1,
opacity = 1,
color = "white",
fillOpacity = 0.6,
options = leafletOptions(pane = "polygons")
) %>%
addLegend(pal = pal, values = ~continent, position = "bottomright")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment