Add a tooltip column of united variable names and values.
add_tooltip(data, ..., titles = snakecase::to_sentence_case, name = "tooltip")
A data frame or tibble.
Arguments passed to select (i.e unquoted variables, tidyselect helpers etc). If no arguments provided, uses all columns.
A function to format the variable names, including in rlang lambda format.
The name of the column created. Defaults to "tooltip".
A data frame or tibble with a column of text
library(ggplot2)
iris %>%
add_tooltip() %>%
head(1)
#> Error in add_tooltip(.): could not find function "add_tooltip"
iris %>%
add_tooltip(tidyselect::contains("Sepal"), Species) %>%
head(1)
#> Error in add_tooltip(., tidyselect::contains("Sepal"), Species): could not find function "add_tooltip"
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))
#> Error in add_tooltip(iris %>% dplyr::mutate(Species = stringr::str_to_sentence(Species)), tidyselect::contains("Sepal"), Species): could not find function "add_tooltip"
p
#> Error in eval(expr, envir, enclos): object 'p' not found
if (requireNamespace("plotly", quietly = TRUE)) {
plotly::ggplotly(p, tooltip = "text")
}
#> Error in plotly::ggplotly(p, tooltip = "text"): object 'p' not found