繁体   English   中英

使用 ggplotly(ggplot2 with plotly)时,你能去掉注释中的跟踪标签吗?

[英]Can you get rid of the trace labels in the annotations when using ggplotly (ggplot2 with plotly)?

使用ggplotly时是否可以删除注释中的跟踪标签?

例如:

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)

在这里,当我在绿色框上输入 hover 时,我将如何摆脱“trace 1”? 不过,我想保留 hover 的要点。

盒子

注意:也发布在这里: https://community.rstudio.com/t/can-you-get-rid-of-the-trace-labels-in-the-annotations-when-using-ggplotly-ggplot2-with-阴谋/129754

您可以尝试使用style并指定hoverinfo如下:

ggplotly(g) %>%
  style(hoverinfo = "skip")

请注意,您可以使用“none”或“skip”来隐藏带有 hover 的工具提示。如果设置了noneskip ,则悬停时不会显示任何信息。 但是,如果none设置,点击和 hover 事件仍然会被触发。

您还可以指明您希望将其应用于哪些跟踪。 如果没有明确包含,那么它将应用于所有跟踪。

要删除特定几何体的注释hoverinfo ,您可以尝试以下操作:

gg <- ggplotly(g)
gg$x$data[[2]]$hoverinfo <- "none"
gg

参考: https://plotly.com/r/reference/#layout

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM