Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在不规则时间设置持久数据点的动画_R_Ggplot2_Gganimate - Fatal编程技术网

R 在不规则时间设置持久数据点的动画

R 在不规则时间设置持久数据点的动画,r,ggplot2,gganimate,R,Ggplot2,Gganimate,我正在尝试设置数据点的动画,使其在特定时间出现。数据点之间没有链接,因此不应该有到它们的轨迹。他们应该在指定的时间和地点出现 然而,可能由于不规则时间间隔和帧渲染的性质,似乎存在大量引入。在前面有很长间隔的数据点之前,这一点非常明显 我在animate()中弄乱了shadow\u trail(),shadow\u wake(),nframes,加上一些其他的transition\u*()函数都没有用 这里是一个10x10网格的代码示例,其中每个正方形在数据中指定的时间弹出,但不是以任何固定间隔弹

我正在尝试设置数据点的动画,使其在特定时间出现。数据点之间没有链接,因此不应该有到它们的轨迹。他们应该在指定的时间和地点出现

然而,可能由于不规则时间间隔和帧渲染的性质,似乎存在大量引入。在前面有很长间隔的数据点之前,这一点非常明显

我在
animate()
中弄乱了
shadow\u trail()
shadow\u wake()
nframes
,加上一些其他的
transition\u*()
函数都没有用

这里是一个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)
库(ggplot2)
库(gganimate)

pos我认为现在发生的是,当你使用
transition\u time
时,你的转换是从一个瓷砖“移动”到下一个瓷砖。您可以使用
transition\u reveal
来防止这种情况

试试这个:

library(ggplot2)
library(gganimate)

pos <- seq(1, 100, 1)

grid_data <- data.frame(pct = pos,
    t = rnorm(100, mean=50, sd=25),
    xpos = (pos-1) %% 10,
    ypos = floor((pos-1) / 10))

grid_data %>%
  ggplot() +
    aes(x=xpos, y=ypos, fill=t) + 
    geom_tile(aes(width=0.95, height=0.95)) +   
    transition_reveal(pct, t, keep_last = TRUE) +
    anim_save("animated_geom_tile.gif")
库(ggplot2)
库(gganimate)
pos这是一部令人着迷、出奇令人满意的动画;-)