要在ggplotly动画中显示的默认帧

时间:2018-01-12 16:01:55

标签: r animation ggplot2 plotly ggplotly

有谁知道如何使用ggplotly()设置初始帧?

4个点的初始状态为1:4,滑块正在添加数字-10:10

假设我有这个动画情节:

library(ggplot2)
library(plotly)

add <- rep(seq(-10, 10, by = .5), each = 4)
x <- 1:4 + add

df <- data.frame(x = x, y = 1, add = add)

plot <- ggplot(df, aes(x, y)) + 
  geom_point(aes(frame = add),
             col = rep(c("yellow", "green", "red", "blue"), length(unique(add))),
             size = 5) +
  theme(axis.line.x = element_line(),
        panel.background = element_blank(), axis.title = element_blank(),
        axis.text.y = element_blank(), axis.ticks.y = element_blank())

ggplotly(plot)

我希望情节从x = 1:4(第21帧)开始,而不是x = -9:-6(第1帧)。

非常感谢!

1 个答案:

答案 0 :(得分:0)

可能是您的数据框中add的排序方式。

df$add <- rev(df$add)
# ... same code as before
ggplotly(plot)

enter image description here