保持缩放时文字大小不变[R]。

问题描述 投票:0回答:1

这对于R上的前辈来说可能很简单,但我在plotly文档和论坛上找不到任何解决方案。基本上,即使用户在整个图中放大缩小,示例文本(如下图代码:"示例文本")的大小也应该保持不变,而不是只放大缩小这部分文本,包括位置等,类似于水印的想法。放大缩小不应该被完全禁止,只针对这段文字。有什么建议吗?

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
r annotations plotly figure r-plotly
1个回答
0
投票

我意识到,yref="paper "和xref="paper "允许我们指定一个位置,这个位置总是相对于情节而言的,y=1指的是情节的顶部,y=0指的是情节的底部。同理,x=1指的是情节的右边,x=0指的是情节的左边。查看详情 此处. 在此基础上,我修改了如下代码。它工作得很完美,如在 23.

Without zoom in/outAfter zoom in

修改后的代码

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
© www.soinside.com 2019 - 2024. All rights reserved.