目标
若要使用“开始/停止/暂停”按钮控制动画,请执行以下操作。
问题
animation
包可以使用saveHTML()
函数(这里的例子)将创建的动画保存为HTML页面。但是它需要"expr
=一个R表达式来计算以创建一个图像序列“作为第一个参数。
但是,gganimate
创建了一个gganim
对象,我似乎找不到一个函数可以将动画保存为带有按钮的HTML页面。可用的anim_save()
函数不保存为HTML。有办法解决这个问题吗?
动画示例代码
如果你有什么想法,请分享。供您参考,我把下面的gganimate
代码从它的网站。
library(ggplot2)
library(gganimate)
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')
发布于 2020-09-19 22:18:37
以下内容在RStudio中适用于我,尽管我没有看到“当前”在gganimate::animate
中作为设备选项列出
library(gganimate)
library(animation)
# name the above gganimate example as p
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')
# pass the animate command to saveHTML
saveHTML(animate(p,
nframes = 10, # fewer frames for simplification
device = "current"),
img.name = "gganimate_plot",
htmlfile = "gg.html")
我得到了一个带有动画控制按钮的html文件&一个包含10个png文件的图像文件夹。
https://stackoverflow.com/questions/63927951
复制