r - 使用 gganimate 导出 gif
问题描述
该包gganimate
创建 gifs(来自此处的 MWE 代码):
library(ggplot2)
#devtools::install_github('thomasp85/gganimate')
library(gganimate)
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
# Here comes the gganimate code
transition_states(
gear,
transition_length = 2,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')
现在怎么能导出这个gif?在以前的(现在存档的)版本中,gganimate
这很简单:
gganimate(p, "output.gif")
gganimate
但是,我在当前包中找不到等效功能。
注意:这个问题似乎与我从中获取 MWE 代码的问题完全相同。但是,gganimate
已更新,在新版本中,在查看器窗格中显示动画与导出动画似乎是不同的问题。
解决方案
gganimate 1.0.6 和 gifski 0.8.6
根据@Ronak Shah 的建议,我使用anim_save()
from the package 添加了一个更新的答案 - 因为它现在gganimate
使用 gifski来呈现输出。.gif
library(ggplot2)
library(gganimate)
# install.package("gifski") #if not already installed
p <- ggplot(mtcars, aes(factor(cyl), mpg)) +
geom_boxplot() +
transition_states(
gear,
transition_length = 2,
state_length = 1
) +
enter_fade() +
exit_shrink() +
ease_aes('sine-in-out')
anim_save("filenamehere.gif", p)
推荐阅读
- android - Android Xamarin 应用程序 - 如何在设备屏幕关闭然后重新打开时保持表单状态?
- python-3.x - 根据字典列表和特定日期条件替换列值 - 使用 if 和 for 循环 - Pandas
- flutter - 重新安排 Flutter 时,本地通知不会在新时间触发
- javascript - 如何使用云功能从我的 Firebase 实时数据库中的 database.ref 正在侦听的节点内部获取数据?
- javascript - 在命令行上关闭由`open`打开的窗口
- ios - 身份验证时如何设计选择SIM卡并在iOS中获取唯一ID?
- php - 在php中删除数组中的重复项
- c++ - 无法修改类复合数据成员
- python - buildozer 制作的 android 应用程序可以使用 glob 和 os 模块吗?
- xml - 谷歌工作表的 importxml 功能是否损坏?