如何从plotly hoverinfo中删除线条和标记符号?

kognpnkq  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(102)

我用plotly画了一个简单的图形,并使用hoverinfo自定义了悬停文本,但悬停文本中有一条线和标记符号,我想删除。下面是一个MWE:

library(tidyverse)
library(plotly)

demand <- tibble(q = seq(0,100,by=2), wtp = 50 - q/2)

plot_ly(
    demand, x = ~q, y = ~wtp, 
    type = "scatter", mode = "lines+markers", 
    text = ~paste(wtp), hoverinfo = "text"
  ) |> 
  layout(hovermode = "y unified")

如何删除悬停信息框内的线条和标记?

wfveoks0

wfveoks01#

根据Kat's的建议,我编辑了hovermode,并试图尽可能地改变hoverlabelspike的格式,以模仿原始图中hovermode = "y unified"的风格。

library(tidyverse)
library(plotly)

demand <- tibble(q = seq(0,100,by=2), wtp = 50 - q/2)

plot_ly(
    demand, x = ~q, y = ~wtp, 
    type = "scatter", mode = "lines+markers", 
    text = ~paste(wtp), hoverinfo = "text"
  ) |> 
  layout(hovermode = "y",
         hoverlabel = list(bgcolor = "#FFF"),
         yaxis = list(showspikes = T, spikemode = "across", 
                      spikesnap = "cursor", spikecolor = "#000",
                      spikedash = "dot", spikethickness = 1))

相关问题