How to add annotations horizontal or vertical reference line in plotly?
<p>I am using plotly for R. output using shiny if that matters.
I want to add annotations to horizontal or vertical reference line created by <code>layout(shapes = )</code>. It should be able to dynamically change position so that it stays visible no matter how plotly graph is zoomed in or out.
<a href="https://i.stack.imgur.com/snDBN.gif" rel="noreferrer">Approximate Example</a></p>

<p>So far I can only find fixed location text. I don't mind if it is dynamically located on axis or arrow pointing to reference lines. </p>

<p>%Edited</p>

<p>I found the sulotion to the problem:</p>

<pre><code>dt &lt;- data.table(x = 1:10, y = rnorm(10))    
annotation &lt;- list(yref = 'paper', xref = "x", y = 0, x = 2, text = "annotation")
plot_ly(type = "scatter", mode = "lines") %&gt;% add_trace(x = dt$x, y = dt$y, mode = "lines") %&gt;% layout(annotations= list(annotation))
</code></pre>

<p>Basically, <code>yref = "paper"</code> allow you to specify a position that is always relative to the plot, <code>y=1</code> refers to the top of plot and <code>y=0</code> refers to the bottom of the plot</p>