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
question from:
https://stackoverflow.com/questions/65935812/remove-plotly-highlight-and-dimming-on-hover-when-mouse-exits-plot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…