如何在 plotly 中添加注释水平或垂直参考线?
How to add annotations horizontal or vertical reference line in plotly?
如果重要的话,我正在使用闪亮的 R.输出。
我想为 layout(shapes = )
创建的水平或垂直参考线添加注释。它应该能够动态改变位置,以便无论绘图图如何放大或缩小,它都保持可见。
Approximate Example
到目前为止我只能找到固定位置的文本。我不介意它是动态地位于轴上还是指向参考线的箭头上。
%已编辑
我找到了解决问题的方法:
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
指的是图的底部
我找到了解决问题的方法:
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 指的是绘图的底部
如果重要的话,我正在使用闪亮的 R.输出。
我想为 layout(shapes = )
创建的水平或垂直参考线添加注释。它应该能够动态改变位置,以便无论绘图图如何放大或缩小,它都保持可见。
Approximate Example
到目前为止我只能找到固定位置的文本。我不介意它是动态地位于轴上还是指向参考线的箭头上。
%已编辑
我找到了解决问题的方法:
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
指的是图的底部
我找到了解决问题的方法:
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 指的是绘图的底部