【问题标题】:Maintain keeping text size the same on zooming on plotly [R]在 plotly 上缩放时保持文本大小相同 [R]
【发布时间】:2020-05-04 12:55:58
【问题描述】:

对于 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】:

    我意识到 yref = "paper" 和 xref = "paper" 允许我们指定一个始终相对于绘图的位置。 y=1 是指绘图的顶部,y=0 是指绘图的底部。类似地,x=1 是指绘图的右侧,x=0 是指绘图的左侧。详情见here。基于此,我将代码修改如下。正如 23 所见,它运行良好。

    修改后的代码

    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
    

    【讨论】:

      猜你喜欢
      • 2014-08-19
      • 2021-10-19
      • 2018-11-12
      • 2019-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多