我想在使用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)


