add_tooltip: Add a tooltip column

View source: R/add_tooltip.R

add_tooltipR Documentation

Add a tooltip column

Description

Add a tooltip column of united variable names and values.

Usage

add_tooltip(data, ..., titles = snakecase::to_sentence_case, name = "tooltip")

Arguments

data

A data frame or tibble.

...

Arguments passed to select (i.e unquoted variables, tidyselect helpers etc). If no arguments provided, uses all columns.

titles

A function to format the variable names, including in rlang lambda format.

name

The name of the column created. Defaults to "tooltip".

Value

A data frame or tibble with a column of text

Examples

library(ggplot2)

iris %>%
  add_tooltip() %>%
  head(1)

 iris %>%
  add_tooltip(tidyselect::contains("Sepal"), Species) %>%
  head(1)

p <- iris %>%
  dplyr::mutate(Species = stringr::str_to_sentence(Species)) |>
  add_tooltip(tidyselect::contains("Sepal"), Species) |>
  ggplot() +
  geom_point(aes(x = Sepal.Width, y = Sepal.Length, col = Species, text = tooltip))

p

if (requireNamespace("plotly", quietly = TRUE)) {
  plotly::ggplotly(p, tooltip = "text")
}

simplevis documentation built on May 31, 2023, 7:02 p.m.