更改gigimate框架标题的标签

Nic*_*ino 16 animation r ggplot2 gganimate

gganimategg_animate()调用渲染动画序列时可以设置浏览选项,似乎没有选项可以更改帧标题,以使观察者更清楚框架所基于的参数是什么.

换句话说,假设frame = year在一个图层中:如何将框架的标题设置为year: ########是当前帧的年份?我错过了什么或是gganimate图书馆的限制吗?

您将如何通过变通方法获得相同的结果?谢谢你的建议.

eip*_*i10 22

更新新gganimateAPI

gganimate已经使用新的API重新设计.现在可以使用下面的代码对框架标题进行动画处理.state_lengthtransition_length设置在给定"状态"(意味着cyl此处的给定值)和状态之间转换所花费的相对时间量:

p = ggplot(mtcars, aes(wt, mpg)) + 
  geom_point() + 
  transition_states(cyl, transition_length=1, state_length=30) +
  labs(title = 'Cylinders: {closest_state}')

animate(p, nframes=40)
Run Code Online (Sandbox Code Playgroud)

gganimate可以github通过运行 来安装devtools::install_github('thomasp85/gganimate')

原始答案

帧的子集值将附加到任何预先存在的标题.因此,您可以添加带有说明文字的标题.例如:

library(gganimate)

p = ggplot(mtcars, aes(wt, mpg, frame=cyl)) + geom_point() + 
    ggtitle("Cylinders: ")

gg_animate(p)
Run Code Online (Sandbox Code Playgroud)

正如您在下面的GIF中所看到的,前缀"Cylinders:"现在被添加到标题之前的值cyl:

在此输入图像描述

  • 如果使用transition_time而不是transition_states,您可以将“{closest_state}”交换为“{frame_time}” (2认同)