更改 gganimate 框架标题的标签
Change label of gganimate frame title
浏览调用gg_animate()
渲染动画序列时可以设置的gganimate
选项,似乎没有选项可以更改帧标题以使其更清晰观察者框架所基于的参数是什么。
换句话说,假设图层中有 frame = year
:如何使框架的标题为 year: ####
,其中 #### 是当前框架的年份?我是不是遗漏了什么或者是 gganimate
库的限制?
您将如何通过变通方法获得相同的结果?
谢谢你的建议。
更新 gganimate
API
gganimate
已重新设计为 new API。框架标题现在可以使用下面的代码进行动画处理。 state_length
和 transition_length
设置在给定“状态”(此处指 cyl
的给定值)和状态之间转换所花费的相对时间量。 closest_state
意味着在状态之间转换时(在这种情况下是 cyl
的整数值)应该显示最接近当前转换值的 cyl
值(例如,因为 cyl
可以是 4、6 或 8,例如 4 和 5 之间的值显示为 4,5 和 6 之间的值显示为 6):
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
可以通过 运行 devtools::install_github('thomasp85/gganimate')
从 github
安装
vignette 有更多关于如何使用新 API 的详细信息。
原答案
框架的子集值附加到任何 pre-existing 标题。因此,您可以添加带有说明文字的标题。例如:
library(gganimate)
p = ggplot(mtcars, aes(wt, mpg, frame=cyl)) + geom_point() +
ggtitle("Cylinders: ")
gg_animate(p)
正如您在下面的 GIF 中看到的,前缀“Cylinders:”现在添加到 cyl
:
值之前的标题中
浏览调用gg_animate()
渲染动画序列时可以设置的gganimate
选项,似乎没有选项可以更改帧标题以使其更清晰观察者框架所基于的参数是什么。
换句话说,假设图层中有 frame = year
:如何使框架的标题为 year: ####
,其中 #### 是当前框架的年份?我是不是遗漏了什么或者是 gganimate
库的限制?
您将如何通过变通方法获得相同的结果? 谢谢你的建议。
更新 gganimate
API
gganimate
已重新设计为 new API。框架标题现在可以使用下面的代码进行动画处理。 state_length
和 transition_length
设置在给定“状态”(此处指 cyl
的给定值)和状态之间转换所花费的相对时间量。 closest_state
意味着在状态之间转换时(在这种情况下是 cyl
的整数值)应该显示最接近当前转换值的 cyl
值(例如,因为 cyl
可以是 4、6 或 8,例如 4 和 5 之间的值显示为 4,5 和 6 之间的值显示为 6):
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
可以通过 运行 devtools::install_github('thomasp85/gganimate')
github
安装
vignette 有更多关于如何使用新 API 的详细信息。
原答案
框架的子集值附加到任何 pre-existing 标题。因此,您可以添加带有说明文字的标题。例如:
library(gganimate)
p = ggplot(mtcars, aes(wt, mpg, frame=cyl)) + geom_point() +
ggtitle("Cylinders: ")
gg_animate(p)
正如您在下面的 GIF 中看到的,前缀“Cylinders:”现在添加到 cyl
: