ggiraph (version 0.7.9)

labeller_interactive: Create a interactive strip label

Description

These function is an helper function to let user add interactivity on facet strip text.

The function adds interactive attributes but does not tell to use them, make sure the theme you are using is specifying the use of element_text_interactive for strip text, for example theme(strip.text = element_text_interactive())

Usage

labeller_interactive(
  custom_label_func = id_label,
  ...,
  .default = ggplot2::label_value
)

Arguments

custom_label_func

a function that returns the result of label_interactive().

...

optional additional arguments for function custom_label_func.

.default

a Labeller function, see label_value()

See Also

id_label(), label_interactive()

Examples

Run this code
# NOT RUN {
library(ggplot2)
library(ggiraph)

gg_jitter <- ggplot(
  mpg, aes(cyl, hwy, group = cyl)) +
  geom_boxplot() +
  facet_wrap(~manufacturer,
             labeller = labeller_interactive(id_label)) +
  theme(strip.text = element_text_interactive())

x <- girafe(ggobj = gg_jitter)
if(interactive()) print(x)


lab_custom <- function(z, prefix = "label: ") {
  label_interactive(label = z, data_id = z, tooltip = paste0(prefix, z))
}

gg_jitter <- ggplot(diamonds, aes(x = x)) +
  geom_density() +
  facet_grid(color ~ cut,
    labeller = labeller(
      cut = labeller_interactive(lab_custom, prefix = "cut: "),
      color = labeller_interactive(lab_custom, prefix = "color: ")
    )) +
  theme_light() +
  theme(
    strip.text.x = element_text_interactive(),
    strip.text.y = element_text_interactive()
  )

x <- girafe(ggobj = gg_jitter, width_svg = 8, height_svg = 5)

if (interactive()) print(x)
# }

Run the code above in your browser using DataLab