缩放动画的控制速度 [英] Control speed of a gganimation

查看:79
本文介绍了缩放动画的控制速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用library(gganimate)时,我希望减慢状态之间的转换速度.

I want to slow the transition speed between states when using library(gganimate).

这是一个小例子:

# devtools::install_github("thomasp85/gganimate")
library(gganimate) # v0.9.9.9999

dat_sim <- function(t_state, d_state) {
  data.frame(
    x = runif(1000, 0, 1),
    y = runif(1000, 0, 1),
    t_state = t_state*d_state
    )
}

dat <- purrr::map_df(1:100, ~ dat_sim(., 1))

ggplot(dat, aes(x, y)) +
  geom_hex(bins = 5) +
  theme_void() +
  lims(x = c(.3, .7),
       y = c(.3, .7)) +
  theme(legend.position = "none") +
  transition_time(t_state)

我的理想行为会慢很多(10-100倍),因此颜色会逐渐演变,没有人会发作.

My ideal behavior would be much slower (10-100x), so color changes gradually evolve and nobody has a seizure.

如果我尝试使用transition_states()进行更多的手动控制,则会得到带有大部分空白帧的gif.我已经尝试了transition_legnth=state_length=的各种组合,但效果不明显.

If I try to use transition_states() for more manual control, I get a gif with mostly blank frames. I've tried various combinations for transition_legnth= and state_length= without a noticeable effect.

ggplot(dat, aes(x, y)) +
  geom_hex(bins = 5) +
  theme_void() +
  lims(x = c(.3, .7),
       y = c(.3, .7)) +
  theme(legend.position = "none") +
  transition_states(t_state, transition_length = .1, state_length = 2)

推荐答案

我在文档 animate函数,该函数可以采用 fps 详细信息参数.

I found in docs animate function which can take fps and detail parameters.

@param fps 动画的帧速率,以帧/秒为单位

@param fps The frame rate of the animation in frames/sec

@param 详细信息每帧要计算的附加帧数

@param detail The number of additional frames to calculate, per frame

结果:

p <- ggplot(dat, aes(x, y)) +
      geom_hex(bins = 5) +
      theme_void() +
      lims(x = c(.3, .7),
           y = c(.3, .7)) +
      theme(legend.position = "none") +
      transition_time(t_state)
animate(p, fps=1)

此外,您还可以指定输出格式,例如 png jpeg svg .

Also there you can specify output format such as png, jpeg, svg.

这篇关于缩放动画的控制速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆