【发布时间】:2020-07-04 08:14:17
【问题描述】:
我正在尝试使用gganimate 创建动画:
library(ggplot2)
library(ggthemes)
library(gifski)
library(gganimate)
load("covid-19-es.Rda")
casos <- ggplot(data,aes(x=Fecha))+geom_point(aes(y=casos,color="Casos"))+geom_point(aes(y=salidas,color="Salidas"))+theme_tufte()+transition_states(Fecha,transition_length=2,state_length=1)+labs(title='Day: {frame_time}')
animate(casos, duration = 5, fps = 20, width =800, height = 600, renderer=gifski_renderer())
anim_save("casos.png")
使用的数据文件是here。
最初我使用 geom_lines 而不是 geom_point,但这会产生错误提示:
Error in seq.default(range[1], range[2], length.out = nframes) :
'from' must be a finite number
和
Error in transform_path(all_frames, next_state, ease, params$transition_length[i], :
transformr is required to tween paths and lines
它要么不喜欢线条,要么不喜欢其中的一对。切换到点,并按照 gganimate 问题中的建议创建文件。但是,这会产生不同类型的错误:
Error: Provided file does not exist
我真的无法弄清楚,因为我根本没有提供任何文件。无论如何尝试保存都会产生
Error: The animation object does not specify a save_animation method
所以我真的不知道我是否做错了什么,使用了已弃用的版本(或包)或什么。
使用的版本
- R 3.6
- ggplot 2_3.3.0
- gganimate 1.0.5
- gifski 0.8.6
【问题讨论】:
-
很好奇您想要动画的样子,因为您在 x 轴上有日期并将其用作构面变量。你想随着时间的推移显示线路吗?在这种情况下,您可能需要
transition_reveal() -
@paqmo 是的,那是我的意图......