【问题标题】:Plotly line annotations with multiple lines用多行绘制行注释
【发布时间】:2020-06-15 20:19:53
【问题描述】:

问题:基本上,我想为mpg(第一行)和disp(第二行)的图中的每一行注释y值。

如何扩展下面的玩具示例代码来实现这一点? 2x add_text() 层不工作...

非常感谢!

plot_ly(mtcars, 
        x = ~wt) %>% 
  add_lines(y = ~mpg,
            text = ~mpg) %>%
  add_text() %>%
  add_lines(y = ~disp,
            text = ~disp) %>%
  add_text()

【问题讨论】:

    标签: r plotly data-visualization


    【解决方案1】:

    由于每个添加都继承自原始的 plot_ly 调用,因此您需要为每个对 add_text 的调用指定 ytext 值。据我所知,它们不会从之前对 add_lines 的调用中继承 ytext 值。

    plot_ly(mtcars, 
            x = ~wt) %>% 
      add_lines(y = ~mpg) %>%
      add_text(y = ~mpg,
               text = ~mpg) %>%
      add_lines(y = ~disp) %>%
      add_text(y = ~disp,
               text = ~disp)
    

    【讨论】:

      猜你喜欢
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 2021-10-21
      • 1970-01-01
      • 2013-03-04
      • 2012-10-15
      • 1970-01-01
      相关资源
      最近更新 更多