Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

r - Remove plotly highlight and dimming on hover when mouse exits plot

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...