add_tooltip: Add a tooltip on a map

Description Usage Arguments Value Examples

Description

Add a tooltip on a map

Usage

1
2
add_tooltip(map, value = "<b>{name}</b><<scale_var>>", as_glue = TRUE,
  .na = "no data")

Arguments

map

A r2d3map htmlwidget object.

value

A formula or a glue string matching columns in data.

as_glue

Use a glue string, if FALSE you can pass a character vector as tooltip.

.na

Value to replace NA values with (if value is a glue string). Use NULL to don't display tooltip if there is NAs.

Value

A r2d3map htmlwidget object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library( r2d3maps )
library( rnaturalearth )

belgium <- ne_states(country = "belgium", returnclass = "sf")

# default
d3_map(shape = belgium) %>%
  add_tooltip()

# glue
d3_map(shape = belgium) %>%
  add_tooltip(value = "{name} ({gn_name})")

# formula
d3_map(shape = belgium) %>%
  add_tooltip(value = ~paste0(name, " (", gn_name, ")"))

dreamRs/r2d3maps documentation built on May 25, 2019, 8:17 a.m.