gpt4 book ai didi

r - 如何在plotly中添加注释水平或垂直引用线?

转载 作者:行者123 更新时间:2023-12-03 21:29:06 25 4
gpt4 key购买 nike

如果重要的话,我正在使用 Shiny 的 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指的是 plotly 的顶部和 y=0指的是 plotly 的底部

最佳答案

我找到了解决问题的方法:

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 - 如何在plotly中添加注释水平或垂直引用线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41267246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com