【发布时间】:2020-09-24 09:30:48
【问题描述】:
我在绘制动画时遇到问题,其中某些图层中的数据仅存在于某些帧中。在下面的示例中,我有一个可以很好地沿 9 帧动画的移动点。但是,当我添加一个点仅存在于某些帧中的另一个图层时,我收到以下错误:
错误:所有层的时间数据必须是同一类
示例:
require(data.table)
require(ggplot2)
require(gganimate)
# 9 points along x=y; present at every time point
dtP1 = data.table(x = 1:9,
y = 1:9,
t = 1:9)
# 3 points along x = 10-y; present at time points 2, 5, 8
dtP2 = data.table(x = c(1, 5, 9),
y = c(9, 5, 1),
t = c(2, 5, 8))
p = ggplot() +
geom_point(data = dtP1,
aes(x = x,
y = y),
color = "#000000") +
geom_point(data = dtP2,
aes(x = x,
y = y),
color = "#FF0000") +
gganimate::transition_time(t) +
gganimate::ease_aes('linear')
pAnim = gganimate::animate(p,
renderer = av_renderer("~/test.mp4"),
fps = 1,
nframes = 9,
height = 400, width = 400)
【问题讨论】: