更改gganimate框架标题的标签

更改gganimate框架标题的标签

本文介绍了更改gganimate框架标题的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

跳过 gganimate 选项,可以在调用 gg_animate()来渲染动画序列时进行设置,似乎没有任何选项可以更改框架标题,从而使观察者可以更清楚地了解框架所基于的参数。



话来说,假设 frame =年在一个层中:我如何使框架的标题为 year:#### ####是当前帧的年份?我是否缺少某些东西?或者它是 gganimate 库的限制吗?



您如何通过获得相同的结果?解决方法?
感谢您的建议。

解决方案

更新新的 gganimate API



gganimate 已重新设计为


Skimming through the options of gganimate that can be set when gg_animate() is called to render the animated sequence, it seems that there is no option to change the frame title so to make it clearer to the observer of what is the parameter that the frame is based on.

In other words, suppose that frame = year in a layer: how do I make the frame's title be year: #### where #### is the year of the current frame? Am I missing something or is it a limitation of the gganimate library?

How would you achieve the same result by a workaround?Thanks for your advice.

解决方案

Update for new gganimate API

gganimate has been redesigned with a new API. The frame title can now be animated with the code below. state_length and transition_length set the relative amount of time spent in a given "state" (meaning a given value of cyl here) and transitioning between states:

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)

gganimate can be installed from github by running devtools::install_github('thomasp85/gganimate')

Original Answer

The frame's subset value is appended to any pre-existing title. You can therefore add a title with explanatory text. For example:

library(gganimate)

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

gg_animate(p)

As you can see in the GIF below, the prefix "Cylinders: " is now added to the title before the value of cyl:

这篇关于更改gganimate框架标题的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:32