【问题标题】:gganimate does not work properly in combination with geom_areagganimate 与 geom_area 结合使用时无法正常工作
【发布时间】:2022-04-17 23:51:57
【问题描述】:

我想用 gganimate 为 ggplot 设置动画,使用 geom_area 在 2000 年到 2050 年间具有不同的值。但是,由于某种原因,如果我包含 view_zoom 以保持 y 轴固定并缩放沿 x 轴向外显示前 50 帧,它在值 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())

【问题讨论】:

    标签: r gganimate geom-area


    【解决方案1】:

    像这样使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2019-12-22
      • 2019-05-03
      • 2015-07-19
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      相关资源
      最近更新 更多