簡體   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