| labeller_interactive {ggiraph} | R Documentation |
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())
labeller_interactive( custom_label_func = id_label, ..., .default = ggplot2::label_value )
custom_label_func |
a function that returns the result
of |
... |
optional additional arguments for function |
.default |
a Labeller function, see |
id_label(), label_interactive()
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)