【发布时间】:2017-08-14 18:01:34
【问题描述】:
我使用gganimate 创建了一个动画情节.gif。问题是输出有重复的图例和标题,我不知道是什么原因造成的。
图例应位于底部,标题应位于图的左下角。关于我在这里做错了什么有什么想法吗?
可重现的例子:
library(gapminder)
library(ggplot2)
library(gganimate)
library(viridis)
t <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
geom_point() +
scale_color_viridis(name="Continent", discrete=TRUE) +
scale_x_log10() +
theme_void() +
theme( legend.position = "bottom", legend.box = "vertical", legend.title.align = 0) +
labs(title = "Year: ") +
labs(caption = " Caption test") +
theme(plot.title = element_text(hjust = 0.5, vjust = 0.05)) +
theme(plot.caption = element_text(hjust = 0, color="gray40", size=10))
gganimate(t, "output_test.gif")
更新 [24-03-2017]:gganimate 的作者 David Robinson 在 Twitter 上向我证实,这种奇怪的行为是由应该很快修复的错误引起的。
与此同时,@hrbrmstr 的解决方案看起来不错。另一种选择是使用旧版本的gganimate,可以这样安装:
library(devtools)
install_github("dgrtwo/gganimate", ref = "26ec501")
【问题讨论】:
-
在您的可重现示例中还需要
library(viridis)。 -
这是 gif 导出过程的一个怪癖:它适用于 mp4
标签: r ggplot2 gif animated-gif gganimate