is it possible to remove the trace labels in the annotations when using ggplotly?
For example:
library(ggplot2)
library(plotly)
g <- ggplot(iris, aes(Sepal.Width, Sepal.Length))
geom_point()
annotate("rect", xmin = 4, xmax = 5, ymin = 4, ymax = 5,
colour = "MediumSeaGreen", fill = "MediumSeaGreen", alpha = 0.3)
ggplotly(g)
Here, how would I get rid of the 'trace 1' when I hover over the green box? I would like to keep the hover on the points though.
Note: Also posted here: https://community.rstudio.com/t/can-you-get-rid-of-the-trace-labels-in-the-annotations-when-using-ggplotly-ggplot2-with-plotly/129754
CodePudding user response:
You can try using style
and specifying hoverinfo
as follows:
ggplotly(g) %>%
style(hoverinfo = "skip")
Note you can use "none" or "skip" to hide the tooltip with hover. If none
or skip
are set, no information is displayed upon hovering. But, if none
is set, click and hover events are still fired.
You can also indicate which traces you'd like this to apply to. If none are explicitly included, then it will apply to all traces.
To remove the annotation hoverinfo
for a specific geom, you can try this:
gg <- ggplotly(g)
gg$x$data[[2]]$hoverinfo <- "none"
gg
Reference: https://plotly.com/r/reference/#layout