在 plotly [R] 上缩放时保持文本大小相同

Maintain keeping text size the same on zooming on plotly [R]

对于 R 的老年人来说可能非常简单,但我无法通过 plotly 文档和论坛找到任何解决方案。基本上,即使用户在整个图中缩放 in/out,示例文本的大小(如下面的代码:"Example Text")也应该保持相同的大小,而无需仅放大和缩小该文本部分,包括类似于水印想法的位置等。缩放 in/out 不应该完全禁用图形,只是针对此文本。有什么建议么? 提前致谢

library(plotly)

density <- density(diamonds$carat)

fig <- plot_ly(x = ~density$x, y = ~density$y, type = 'scatter', mode = 'lines', fill = 'tozeroy')
fig <- fig %>% layout(xaxis = list(title = 'Carat'),
                      yaxis = list(title = 'Density'),
                      annotations=list(text="Example Text", "showarrow" = F, font=list(size = 40))
                      )
fig

我意识到 yref = "paper" 和 xref = "paper" 允许我们指定一个始终相对于绘图的位置。 y=1 指的是图的顶部,y=0 指的是图的底部。类似地,x=1 指的是图的右侧,x=0 指的是图的左侧。查看详细信息 here. Based on that, I have modified the code as below. It is working perfectly as seen on 2 and 3。

修改后的代码

library(plotly)

density <- density(diamonds$carat)

fig <- plot_ly(x = ~density$x, 
               y = ~density$y, 
               type = 'scatter', 
               mode = 'lines', 
               fill = 'tozeroy')
fig <- fig %>% layout(xaxis = list(title = 'Carat'),
                      yaxis = list(title = 'Density'),
                      annotations=list(text="Example Text", 
                                       xref = "paper",
                                       yref = "paper",
                                       opacity = 0.4,
                                       "showarrow" = F, 
                                       font=list(size = 40)
                                       )
                      )
fig