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 layout(shapes = )
. It should be able to dynamically change position so that it stays visible no matter how plotly graph is zoomed in or out.
Approximate Example
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.
%Edited
I found the sulotion to the problem:
dt <- data.table(x = 1:10, y = rnorm(10))
annotation <- list(yref = 'paper', xref = "x", y = 0, x = 2, text = "annotation")
plot_ly(type = "scatter", mode = "lines") %>% add_trace(x = dt$x, y = dt$y, mode = "lines") %>% layout(annotations= list(annotation))
Basically, yref = "paper"
allow you to specify a position that is always relative to the plot, y=1
refers to the top of plot and y=0
refers to the bottom of the plot