Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

opts_hover

Hover effect settings


Description

Allows customization of the rendering of graphic elements when the user hovers over them with the cursor (mouse pointer). Use opts_hover for interactive geometries in panels, opts_hover_key for interactive scales/guides and opts_hover_theme for interactive theme elements. Use opts_hover_inv for the effect on the rest of the geometries, while one is hovered (inverted operation).

Usage

opts_hover(css = NULL, reactive = FALSE)

opts_hover_inv(css = NULL)

opts_hover_key(css = NULL, reactive = FALSE)

opts_hover_theme(css = NULL, reactive = FALSE)

Arguments

css

css to associate with elements when they are hovered. It must be a scalar character. It can also be constructed with girafe_css, to give more control over the css for different element types.

reactive

if TRUE, in Shiny context, hovering will set Shiny input values.

Note

IMPORTANT: When applying a fill style with the css argument, be aware that the browser's CSS engine will apply it also to line elements, if there are any that use the hovering feature. This will cause an undesired effect.

To overcome this, supply the argument css using girafe_css, in order to set the fill style only for the desired elements.

See Also

Other girafe animation options: girafe_options(), opts_selection(), opts_sizing(), opts_toolbar(), opts_tooltip(), opts_zoom()

Examples

library(ggplot2)

dataset <- mtcars
dataset$carname = row.names(mtcars)

gg <- ggplot(
  data = dataset,
  mapping = aes(x = wt, y = qsec, color = disp,
                tooltip = carname, data_id = carname) ) +
  geom_point_interactive() + theme_minimal()

x <- girafe(ggobj = gg)
x <- girafe_options(x,
  opts_hover(css = "fill:wheat;stroke:orange;r:5pt;") )
if( interactive() ) print(x)

ggiraph

Make 'ggplot2' Graphics Interactive

v0.7.10
GPL-3
Authors
David Gohel [aut, cre], Panagiotis Skintzos [aut], Mike Bostock [cph] (d3.js), Speros Kokenes [cph] (d3-lasso), Eric Shull [cph] (saveSvgAsPng js library), Eric Book [ctb] (hline and vline geoms)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.