简体   繁体   English

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

[英]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 的工具提示。如果设置了noneskip ,则悬停时不会显示任何信息。 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.

相关问题 使用ggplotly将ggplot2转换为plotly时,曲线混乱 - curves messed up when converting ggplot2 to plotly using ggplotly 使用ggplotly时,不会解析ggplot2图形中的标签(注释) - Labels (annotate) in ggplot2 graphics are not parsed when using ggplotly 使用ggplot2和ggplotly创建Sankey Diagram - Creating Sankey Diagram using ggplot2, plotly and ggplotly R plotly:使用ggplotly()时如何保持ggplot2 geom_bar()的宽度参数 - R plotly: How to keep width parameter of ggplot2 geom_bar() when using ggplotly() 如何在使用`ggplotly`将ggplot2转移到图表时更改图例位置? - How to change the legend position when transfer ggplot2 to plotly using `ggplotly`? ggplot2和ggplotly之间的行为不同 - Different behavior between ggplot2 and plotly using ggplotly 使用ggplotly时,在plotly中的标签上格式化鼠标 - Formatting mouse over labels in plotly when using ggplotly R plotly:用ggplotly转换ggplot2时,保留两个图例的外观 - R plotly: preserving appearance of TWO legends when converting ggplot2 with ggplotly 在R中以绘图方式在子图之间共享轴和图例(ggplot2中的构面和使用ggplotly不起作用) - Sharing axes and legends between subplots in plotly in R (faceting in ggplot2 and using ggplotly doesn't work) 使用r中的ggplot2在工具提示中编辑用于绘制地图的标签 - Edit labels in tooltip for plotly maps using ggplot2 in r
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM