Learn R Programming

ggvis (version 0.3.0.1)

add_tooltip: Add tooltips to a plot.

Description

Add tooltips to a plot.

Usage

add_tooltip(vis, html, on = c("hover", "click"))

Arguments

vis
Visualisation to add tooltips to.
html
A function that takes a single argument as input. This argument will be a list containing the data in the mark currently under the mouse. It should return a string containing HTML or NULL to hide tooltip for the current element.
on
Should tooltips appear on hover, or on click?

Examples

Run this code
all_values <- function(x) {
  if(is.null(x)) return(NULL)
  paste0(names(x), ": ", format(x), collapse = "<br />")
}

base <- mtcars %>% ggvis(x = ~wt, y = ~mpg) %>%
  layer_points()
base %>% add_tooltip(all_values, "hover")
base %>% add_tooltip(all_values, "click")

Run the code above in your browser using DataLab