Skip to contents

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)
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#>                                                                                             tooltip
#> 1 Sepal length: 5.1<br>Sepal width: 3.5<br>Petal length: 1.4<br>Petal width: 0.2<br>Species: setosa

 iris %>%
  add_tooltip(tidyselect::contains("Sepal"), Species) %>%
  head(1)
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#>                                                    tooltip
#> 1 Sepal length: 5.1<br>Sepal width: 3.5<br>Species: setosa

if (requireNamespace("ggiraph", quietly = TRUE)) {
p <- iris %>%
  add_tooltip(tidyselect::contains("Sepal"), Species) %>%
  gg_blank(x = Sepal.Width,
           y = Sepal.Length,
           col = Species,
           facet = Species) +
  ggiraph::geom_point_interactive(aes(tooltip = tooltip))

  ggiraph::girafe(ggobj = p, width_svg = 5, height_svg = 4)
}
#>  For further ggblanket information, see https://davidhodge931.github.io/ggblanket/
#> This message is displayed once every 8 hours.