【问题标题】:How to add constant line to animated plot in plotly如何在情节中向动画情节添加恒定线
【发布时间】:2019-04-25 08:14:12
【问题描述】:

我在 R 中使用 plotly 包,需要制作一个动画图,它将我的数据集中的数据与未连接到数据集中数据的恒定阈值相结合。

代码在没有框架的情况下工作正常(在这种情况下,情节没有动画)。如果我添加行

frame = g

我收到以下错误:列 frame 的长度必须为 1 或 10000,而不是 3

情节也适用于框架,但没有“add_lines”部分。

我怎样才能摆脱错误并在每一帧中都有恒定线?

代码如下:

library(plotly)

a <- c(0.006, 0.008, 0.10)
b <- c(0.20, 0.15, 0.22)
g <- c('first', 'second', 'third')

p <- plot_ly(
  x = a,
  y = b,
  frame = g,
  type = 'scatter',
  mode = 'markers'
) %>%
  add_lines (x = seq(0.005, 0.012,length=10000), 
             y =  0.001/seq(0.005, 0.012, length=10000),
             showlegend = FALSE)

p

【问题讨论】:

    标签: r plot plotly scatter-plot r-plotly


    【解决方案1】:

    我猜,这样就行了?

    p <- plot_ly(
      x = a,
      y = b,
      frame = g,
      type = 'scatter',
      mode = 'markers') %>%
      add_lines (x = seq(0.005, 0.012,length=10000), 
                 y =  0.001/seq(0.005, 0.012, length=10000),
                 inherit = FALSE,
                 showlegend = FALSE)
    
    print(p)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 2014-05-11
      • 2016-04-29
      • 1970-01-01
      • 2023-02-07
      • 1970-01-01
      相关资源
      最近更新 更多