Examples for 'tmap::tmap_leaflet'


Create a leaflet widget from a tmap object

Aliases: tmap_leaflet

Keywords:

### ** Examples

# world choropleth/bubble map of the world
data(World, metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100

map1 <- tm_shape(metro) +
        tm_bubbles("pop2010", col = "growth",
                           border.col = "black", border.alpha = .5,
                           style="fixed", breaks=c(-Inf, seq(0, 6, by=2), Inf),
                           palette="-RdYlBu", contrast=1,
                           title.size="Metro population",
                           title.col="Growth rate (%)", id="name") +
        tm_layout(legend.bg.color = "grey90", legend.bg.alpha=.5, legend.frame=TRUE)


lf <- tmap_leaflet(map1)
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
Variable(s) "growth" contains positive and negative values, so midpoint is set to 0. Set midpoint = NA to show the full spectrum of the color palette.
Legend for symbol sizes not available in view mode.
# show leaflet widget
lf
Error in loadNamespace(name): there is no package called 'webshot'
# add marker
require(leaflet)
Loading required package: leaflet
lf %>% leaflet::addMarkers(2.2945, 48.8582, popup = "Eiffel tower")
Error in loadNamespace(name): there is no package called 'webshot'
## Not run: 
##D # alternative
##D eiffelTower <- geocode_OSM("Eiffel Tower, Paris", as.SPDF = TRUE)
##D 
##D map1 + 
##D tm_shape(eiffelTower) +
##D 	tm_markers()
## End(Not run)

[Package tmap version 3.3-4 Index]