我正在尝试为数据点设置动画以在特定时间出现。数据点没有相互链接,因此应该没有往返它们的踪迹。他们应该在指定的时间和地点出现。
然而,可能由于不规则的时间间隔和帧渲染的性质,似乎有很多引入。在一个数据点之前有很长的时间间隔之前,它真的很明显。
我弄乱了shadow_trail()
, shadow_wake()
, nframes
inanimate()
以及其他一些transition_*()
功能都无济于事。
这是一个 10x10 网格的代码示例,其中每个方块在数据中指定的时间弹出,但不是在任何固定间隔。您可以看到一些方块前往目的地。它们应该就地出现。
library(ggplot2)
library(gganimate)
pos <- seq(1, 100, 1)
# Squares on a 10x10 grid that pop up at random times
grid_data <- data.frame(pct = pos,
t = rnorm(100, mean=50, sd=25),
xpos = (pos-1) %% 10,
ypos = floor((pos-1) / 10))
p <- ggplot(grid_data, aes(x=xpos, y=ypos, fill=t)) # plot tiles, color by time of arrival
p <- p + geom_tile(aes(width=0.95, height=0.95)) # tiles with some gap around them
p <- p + transition_time(time=grid_data$t) # Show data points by their time
p <- p + shadow_mark(past=TRUE, future=FALSE) # Keep showing past (prior) data points
animate(p)