在2000年到2050年期间,我想使用具有不同值的gganimate使用geom_area来绘制一个ggplot。然而,由于某种原因,如果我包括view_zoom来保持y轴的固定,并且在大约前50帧的x轴上放大,它会在值1999.95到2000.05之间缩放,而对于最后的50帧,它会显示x轴的整个范围(从2000年到2050年)。我如何解决这个问题,使它逐渐放大,直到它显示整个范围的x轴结束?
library(gganimate)
library(tidyverse)
gif_data <-
tibble(year = as.numeric(2000:2050),
value = as.numeric(seq(0.5, 0.3, length.out = 51)))
gif <-
ggplot(gif_data,
aes(x = year,
y = value)) +
geom_area() +
transition_reveal(year) +
ggtitle('Frame {frame} of {nframes}') +
view_zoom(fixed_y = TRUE)
animate(gif,
fps = 10,
duration = 10,
height = 337.5,
width = 600,
units = "px",
res = 50,
renderer = gifski_renderer())
anim_save("~/Desktop/gif.gif",
animation = last_animation())

发布于 2022-04-17 15:51:57
使用view_follow代替view_zoom,如下所示:
gif <-
ggplot(gif_data,
aes(x = year,
y = value)) +
geom_area() +
transition_reveal(year) +
ggtitle('Frame {frame} of {nframes}') +
view_follow(fixed_y = TRUE)https://stackoverflow.com/questions/69699583
复制相似问题