layout(hovermode = "x unified")Plotly 提供了通过添加或显示可移动的水平或垂直“尖峰线”的选项layout(hovermode = "y unified")(请参阅文档)。例如:
library(plotly)
x <- seq(from = 0, to = 2*pi, length = 100)
y <- sin(x)
fig <- plot_ly(x = x, y = y, type = "scatter", mode = "markers")
fig <- fig %>% layout(hovermode = "x unified")
fig
Run Code Online (Sandbox Code Playgroud)
使用跟随光标的垂直线创建此图:
我尝试像这样修改布局:
fig <- fig %>% layout(hovermode = "x unified") %>% layout(hovermode = "y unified")
# or
fig <- fig %>% layout(hovermode = c("x unified", "y unified"))
# …Run Code Online (Sandbox Code Playgroud)