控制动画的速度
Control speed of a gganimation
我想在使用 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-100x),因此颜色变化会逐渐演变并且没有人会癫痫发作。
如果我尝试使用 transition_states()
进行更多手动控制,我会得到一个大部分为空白帧的 gif。我尝试了 transition_legnth=
和 state_length=
的各种组合,但没有明显效果。
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)
我在 docs animate
函数中找到了 fps 和 detail 参数。
@param fps The frame rate of the animation in frames/sec
@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。
我想在使用 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-100x),因此颜色变化会逐渐演变并且没有人会癫痫发作。
如果我尝试使用 transition_states()
进行更多手动控制,我会得到一个大部分为空白帧的 gif。我尝试了 transition_legnth=
和 state_length=
的各种组合,但没有明显效果。
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)
我在 docs animate
函数中找到了 fps 和 detail 参数。
@param fps The frame rate of the animation in frames/sec
@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。