How to add annotations horizontal or vertical reference line in plotly?

人走茶凉 提交于 2019-12-14 01:59:36

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/41267246/how-to-add-annotations-horizontal-or-vertical-reference-line-in-plotly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!