[英]Can you get rid of the trace labels in the annotations when using ggplotly (ggplot2 with plotly)?
is it possible to remove the trace labels in the annotations when using ggplotly?使用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?在这里,当我在绿色框上输入 hover 时,我将如何摆脱“trace 1”? I would like to keep the hover on the points though.
不过,我想保留 hover 的要点。
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注意:也发布在这里: https://community.rstudio.com/t/can-you-get-rid-of-the-trace-labels-in-the-annotations-when-using-ggplotly-ggplot2-with-阴谋/129754
You can try using style
and specifying hoverinfo
as follows:您可以尝试使用
style
并指定hoverinfo
如下:
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.请注意,您可以使用“none”或“skip”来隐藏带有 hover 的工具提示。如果设置了
none
或skip
,则悬停时不会显示任何信息。 But, if none
is set, click and hover events are still fired.但是,如果
none
设置,点击和 hover 事件仍然会被触发。
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:要删除特定几何体的注释
hoverinfo
,您可以尝试以下操作:
gg <- ggplotly(g)
gg$x$data[[2]]$hoverinfo <- "none"
gg
Reference: https://plotly.com/r/reference/#layout参考: https://plotly.com/r/reference/#layout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.