title: How to create plot with both vertical and horizontal spikelines in plotly?
body: <p>Plotly offers the option to display a moveable horizontal or vertical &quot;spikeline&quot; by adding <code>layout(hovermode = &quot;x unified&quot;)</code> or <code>layout(hovermode = &quot;y unified&quot;)</code> (see <a href="https://plotly.com/r/reference/layout/#layout-hovermode" rel="nofollow noreferrer">documentation</a>). For example:</p>
  <pre><code>library(plotly)
  
  x &lt;- seq(from = 0, to = 2*pi, length = 100)
  y &lt;- sin(x)
  fig &lt;- plot_ly(x = x, y = y, type = &quot;scatter&quot;, mode = &quot;markers&quot;)
  fig &lt;- fig %&gt;% layout(hovermode = &quot;x unified&quot;)
  fig
  </code></pre>
  <p>creates this plot with a vertical line that follows the cursor:</p>
  <p><a href="https://i.stack.imgur.com/ziSba.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ziSba.png" alt="enter image description here" /></a></p>
  <p>I would like to have both the vertical and the horizontal spikeline displayed. Like this:
  <a href="https://i.stack.imgur.com/9gyRz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9gyRz.png" alt="enter image description here" /></a></p>
  <p>I tried to modify the layout like this:</p>
  <pre><code>fig &lt;- fig %&gt;% layout(hovermode = &quot;x unified&quot;) %&gt;% layout(hovermode = &quot;y unified&quot;)
  # or
  fig &lt;- fig %&gt;% layout(hovermode = c(&quot;x unified&quot;, &quot;y unified&quot;))
  # or
  fig &lt;- fig %&gt;% layout(hovermode = &quot;x unified|y unified&quot;)
  </code></pre>
  <p>None of this worked. Would anybody have a suggestion?</p>