【问题标题】:gganimate:combine barplot with lineplotgganimate:将条形图与线图相结合
【发布时间】:2023-03-22 20:52:01
【问题描述】:
library(ggplot2)
library(tidyverse)
library(gganimate)

set.seed(321)
year <- 2001:2021
value <- runif(n = length(year))*100%>% round(digits = 2)

df <- data.frame(year, value) %>%
  mutate(cumsum = cumsum(value))


df %>% 
  ggplot(aes(x = year)) +
  geom_col(aes(y = value)) +
  geom_line(aes(y = cumsum)) +
  transition_states(year) +
  shadow_mark()

如何获得多年来的条形图和线图的动画,上面的代码有错误。 transform_path 错误(all_frames, next_state, ease, params$transition_length[i], : 补间路径和线条需要转换器

【问题讨论】:

    标签: r gganimate


    【解决方案1】:

    安装transformr() package

    library(ggplot2)
    library(tidyverse)
    library(gganimate)
    library(transformr)
    
    set.seed(321)
    year <- 2001:2021
    value <- runif(n = length(year))*100%>% round(digits = 2)
    
    df <- data.frame(year, value) %>%
      mutate(cumsum = cumsum(value))
    
    
    df %>% 
      ggplot(aes(x = year)) +
      geom_col(aes(y = value)) +
      geom_line(aes(y = cumsum)) +
      transition_states(year) +
      shadow_mark()
    

    【讨论】:

    • 谢谢,但没有线条动画。 0sgeom_path:每组只包含一个观察。需要调整群体审美吗?在 9.90 秒时插入图像 100 (100%)...编码为 gif...完成!
    • 有了transformr和下面的代码,barplot就没有阴影了。 df %&gt;% ggplot(aes(x = year)) + geom_col(aes(y = value)) + geom_line(aes(y = cumsum)) + transition_reveal(year) + shadow_mark()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 2023-02-07
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    相关资源
    最近更新 更多