如何从绘图悬停信息中删除线条和标记符号?

问题描述 投票:0回答:1

我正在使用

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")

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

r plotly
1个回答
0
投票

按照Kat的建议,我编辑了

hovermode
,并尝试尽可能改变
hoverlabel
spike
的格式,以模仿原剧情中
 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))

© www.soinside.com 2019 - 2024. All rights reserved.