tmap_leaflet: Create a leaflet widget from a tmap object

Description Usage Arguments Value See Also Examples

View source: R/print.R

Description

Create a leaflet widget from a tmap object. An interactive map (see tmap_mode) is an automatically generated leaflet widget. With this function, this leaflet widget is obtained, which can then be changed or extended by using leaflet's own methods.

Usage

1
2
3
4
5
6
7
8
tmap_leaflet(
  x,
  mode = "view",
  show = FALSE,
  add.titles = TRUE,
  in.shiny = FALSE,
  ...
)

Arguments

x

tmap object. A tmap object is created with qtm or by stacking tmap-elements.

mode

the mode of tmap, which is set to "view" in order to obtain the leaflet object. See tmap_mode for details.

show

should the leaflet map be shown? FALSE by default

add.titles

add titles to leaflet object

in.shiny

is the leaflet output going to be used in shiny? If so, two features are not supported and therefore disabled: facets and colored backgrounds.

...

arguments passed on to print.tmap

Value

leaflet object

See Also

tmapOutput for tmap in Shiny, tmap_mode, tm_view, print.tmap

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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)

# show leaflet widget
lf

# add marker
require(leaflet)
lf %>% leaflet::addMarkers(2.2945, 48.8582, popup = "Eiffel tower")

## Not run: 
# alternative
eiffelTower <- geocode_OSM("Eiffel Tower, Paris", as.SPDF = TRUE)

map1 + 
tm_shape(eiffelTower) +
	tm_markers()

## End(Not run)

tmap documentation built on June 16, 2021, 9:10 a.m.