Created
January 21, 2020 23:23
-
-
Save PaulC91/8e95071bbc6f4856e9713d886dd2927e to your computer and use it in GitHub Desktop.
render place tile labels above polygons in R leaflet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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