'How to create plot with both vertical and horizontal spikelines in plotly?
Plotly offers the option to display a moveable horizontal or vertical "spikeline" by adding layout(hovermode = "x unified")
or layout(hovermode = "y unified")
(see documentation). For example:
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
creates this plot with a vertical line that follows the cursor:
I would like to have both the vertical and the horizontal spikeline displayed. Like this:
I tried to modify the layout like this:
fig <- fig %>% layout(hovermode = "x unified") %>% layout(hovermode = "y unified")
# or
fig <- fig %>% layout(hovermode = c("x unified", "y unified"))
# or
fig <- fig %>% layout(hovermode = "x unified|y unified")
None of this worked. Would anybody have a suggestion?
Solution 1:[1]
Check out this resource on 3d plots - I had the same issue and applied the xaxis = list() and yaxis = list() arguments to layout() and it worked well for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | gloop |