【发布时间】:2019-04-27 23:52:29
【问题描述】:
我想使用 gganimate 为一些数据制作动画。以他们的 github 页面为例,我对其进行了一些更改以反映我的情况。 X 轴是日期,我希望所有帧的徽标都位于同一位置。
可重现的代码:
library(magick)
library(gapminder)
library(ggplot2)
library(rsvg)
library(gganimate)
tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 400)
(p <- ggplot(gapminder, aes(year, lifeExp, size = pop, colour = country)) +
geom_point(alpha = 0.7, show.legend = FALSE) +
scale_colour_manual(values = country_colors) +
scale_size(range = c(2, 12)) +
scale_x_log10() +
annotation_raster(tiger, ymin = 75, ymax = 100, xmin = 1965, xmax = 2005) )
# here the animate part (not needed just for ilustrative purposes)
p + labs(title = 'Year: {frame_time}', x = 'Year', y = 'life expectancy') +
transition_time(year) +
ease_aes('linear')
问题是当 x 轴不是日期时,我可以在任何图表中绘制徽标。
我怀疑这个问题与日期类型有关,但到目前为止没有成功。
【问题讨论】:
-
我对此感到困惑。日期是一种特殊的数据类型。您所拥有的“日期”只是编码为整数的年份。对数刻度是您想要做的特定事情吗?
-
如果您尝试沿 log10 比例放置图像,则需要根据该比例设置其坐标。 log10(1965) 是 3.293363,log10(2005) 是 3.302114。我也不认为动画与它有任何关系——问题在于放置注释。如果该展示位置与
transition_time无关,则不应受到动画的影响。