我正在使用
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")
如何删除悬停信息框中的线条和标记?
按照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))