2

I would like to remove the highlight effect on selected data, and corresponding dimming effect on non-selected data, produced by hovering over data in a ggplotly object where plotly::highlight() has been used, but ONLY when the mouse exits the plot. Essentially I would like to reset a ggplotly plot to its un-highlighted state whenever the mouse exits the plot.

Please find a minimum reproducible example below.

Any help would be greatly appreciated!

library(ggplot2)
library(plotly)
library(magrittr)

# Prepare data
data <- mtcars

# Establish highlight key 
data <- highlight_key(data, ~cyl)

# Plot data
plot <- ggplot(data, aes(x = mpg, y = hp, color = cyl)) +
  geom_point()

# Convert to plotly plot using ggplotly, and highlight data
plot2 <- ggplotly(plot, tooltip = "cyl") %>%
  highlight(on = "plotly_hover", off = "plotly_deselect")

# Display plot
plot2
ZekeMarshall
  • 131
  • 5

0 Answers0