如何在绘图中添加水平或垂直参考线的注释? [英] How to add annotations horizontal or vertical reference line in plotly?
问题描述
如果这很重要,我正在使用闪亮的R.输出进行绘图.
我想将注释添加到由layout(shapes = )
创建的水平或垂直参考线.它应该能够动态地改变位置,以使它无论在图形上如何放大或缩小都保持可见.
近似示例
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))
基本上,yref = "paper"
允许您指定始终相对于图的位置,y=1
指图的顶部,而y=0
指图的底部
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
推荐答案
我找到了解决问题的方法:
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))
基本上,yref ="paper"允许您指定始终相对于图的位置,y = 1表示图的顶部,y = 0表示图的底部
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
这篇关于如何在绘图中添加水平或垂直参考线的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!