Cam*_*epo 14 animation r ggplot2 shiny plotly
如何在最终帧上进行绘制动画加载.也就是说,当情节加载时,我希望它加载到最后一帧(例如2017).默认情况下,它会加载到第一帧(例如1960).之后,当用户点击播放时,动画应该从第一帧开始(例如,1960)
animation_opts(frame = frame, transition = 0, redraw = FALSE) %>%
animation_slider(currentvalue = list(prefix = "Year"))
Run Code Online (Sandbox Code Playgroud)
这不是一个完整的答案,但由于还没有其他答案,我决定发布我能做的最好的答案,也许其他人有改进的想法?
有一个函数animation_slider(),它接受参数active,可以设置滑块上的活动框架。然而,这不会改变图中的活动帧...所以我们的想法是添加一个帧 0(正如 Siyang.Hu 在评论中也提到的那样)并将其与活动帧结合起来。此解决方案的缺点显然是,当您在动画滑块上向后移动时,始终会出现第 0 帧。
# sample data
df = data.frame(a=seq(1,20),b=seq(1,20),frame=seq(1,20))
# add initial frame
init_frame = 10
df = rbind(df[df$frame==10,],df)
df$frame[1]=0
library(plotly)
plot_ly(df,x=~a,y=~b,frame=~frame) %>% animation_slider(active=init_frame)
Run Code Online (Sandbox Code Playgroud)