Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
绘图累积动画不适用于R中的子绘图_R_Plotly - Fatal编程技术网

绘图累积动画不适用于R中的子绘图

绘图累积动画不适用于R中的子绘图,r,plotly,R,Plotly,我有两个plotlyplots,其中包含单独工作的累积动画。但是,如果我使用子地块将它们组合起来,它们就不起作用了。是否可以为2个组合图设置动画?以下是一个可复制的示例: library(plotly) accumulate_by <- function(dat, var) { var <- lazyeval::f_eval(var, dat) lvls <- plotly:::getLevels(var) dats <- lapply(seq_along(

我有两个
plotly
plots,其中包含单独工作的累积动画。但是,如果我使用
子地块将它们组合起来,它们就不起作用了。是否可以为2个组合图设置动画?以下是一个可复制的示例:

library(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)
}

library(MASS)
data(Traffic)


# data 1
Traffic1 <- Traffic %>%
  filter(year==1961) %>% 
  accumulate_by(~day)

# plot1
y_plot <- plot_ly(data = Traffic1,
                  x = ~day,
                  y = ~y,
                  frame = ~frame,
                  type = "scatter") %>%  
animation_slider(
  currentvalue = list(
    prefix = "Day"
  )
)


# data 2
Traffic2 <- Traffic %>%
  filter(year==1962) %>% 
  accumulate_by(~day)

# plot 2
y_plot2 <- plot_ly(data = Traffic2,
                  x = ~day,
                  y = ~y,
                  frame = ~frame,
                  type = "scatter") %>%  
  animation_slider(
    currentvalue = list(
      prefix = "Day"
    )
  )


# combined plot
subplot(y_plot, y_plot2)
library(plotly)

我不确定这是否可能。这个问题一直没有答案。但是,也许有一种替代方法可以使用
ggplot2
ggplotly
facet\u grid

你可以试试这个:

#Create a new data frame
Traffic1$Traffic <- 1
Traffic2$Traffic <- 2
Traffic <- rbind(Traffic1, Traffic2)

gg <- ggplot(Traffic, aes(x=day, y=y)) +
    geom_point(aes(frame = frame), color = "blue") + facet_grid(Traffic~.) + theme_bw()
ggplotly(gg)
#创建新的数据帧
流量1$流量