从绘图对象中删除悬停信息文本

时间:2018-12-14 22:25:52

标签: r hover plotly

我正在plotly中创建一个R对象:

library(plotly)
p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, text = ~Species, hoverinfo="text",
             marker = list(size = 10,
                           color = 'rgba(255, 182, 193, .9)',
                           line = list(color = 'rgba(152, 0, 0, .8)',
                                       width = 2))) %>%
  layout(title = 'Styled Scatter',
         yaxis = list(zeroline = FALSE),
         xaxis = list(zeroline = FALSE))

如您所见,它包括hoverino

然后在某个时候我要删除该hoverinfo层。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

style(hoverinfo = 'none')

因此将它们放在一起:

(p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, text = ~Species, hoverinfo="text",
             marker = list(size = 10,
                           color = 'rgba(255, 182, 193, .9)',
                           line = list(color = 'rgba(152, 0, 0, .8)',
                                       width = 2))) %>%
  layout(title = 'Styled Scatter',
         yaxis = list(zeroline = FALSE),
         xaxis = list(zeroline = FALSE)) %>% 
  style(hoverinfo = 'none'))