Subplot Plotly 中的多个动画

use*_*882 5 r ggplot2 plotly

尝试仅使用一个播放按钮在 R 中使用 Plotly 为多个绘图设置动画

为了获得我使用的每个数据条目的帧值:

    accumulate_by <- function(dat, var) {
  var <- lazyeval::f_eval(var, dat)
  lvls <- plotly:::getLevels(var)
  dats <- lapply(seq_along(lvls), function(x) {
    cbind(dat[var %in% lvls[seq(1, x)], ], frame = lvls[[x]])
  })
  dplyr::bind_rows(dats)
}



    d <- df3 %>% select(gen,score) %>% 
      accumulate_by(~gen)
    d2 <- df3 %>% select(gen,cpg_margin) %>% 
      accumulate_by(~gen)
Run Code Online (Sandbox Code Playgroud)

接下来我创建情节

p1 <- d %>%
  plot_ly(
    x = ~gen, 
    y = ~score,
    frame = ~frame, 
    type = 'scatter',
    mode = 'lines', 
    line = list(simplyfy = F)
  ) %>% 
  layout(
    xaxis = list(
      title = "title",
      zeroline = F
    ),
    yaxis = list(
      title = "title",
      zeroline = F
    ),
    title = "title"
  ) %>% 
  animation_opts(
    frame = 100, 
    transition = 0, 
    redraw = FALSE
  ) 

p2 <- d %>%
  plot_ly(
    x = ~gen, 
    y = ~score2,
    frame = ~frame, 
    type = 'scatter',
    mode = 'lines', 
    line = list(simplyfy = F)
  ) %>% 
  layout(
    xaxis = list(
      title = "title",
      zeroline = F
    ),
    yaxis = list(
      title = "title",
      zeroline = F
    ),
    title = "title"
  ) %>% 
  animation_opts(
    frame = 100, 
    transition = 0, 
    redraw = FALSE
  ) 
Run Code Online (Sandbox Code Playgroud)

最后将两个图合并的子图

p <- subplot(p1, p2) %>%
  animation_slider(
    hide = T
    ) %>%
  animation_button(
    x = 1, xanchor = "right", y = 0, yanchor = "bottom"
  )
Run Code Online (Sandbox Code Playgroud)

但是播放按钮不会启动动画。我是否也需要在图中链接播放按钮?