如果这很重要的话,我正在使用“plotly”来进行 R. 输出,并使用“shiny”。
我想向由以下命令创建的水平或垂直参考线添加注释layout(shapes = )
。它应该能够动态改变位置,以便无论图表如何放大或缩小,它都保持可见。近似示例 https://i.stack.imgur.com/snDBN.gif
到目前为止我只能找到固定位置的文本。我不介意它是否动态位于指向参考线的轴或箭头上。
%Edited
我找到了问题的解决方案:
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 指绘图的底部
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)