【问题标题】:Issue creating animation with Date vs Value and Investors with gganimate使用 Date vs Value 和 Investors 使用 gganimate 创建动画的问题
【发布时间】:2019-01-30 20:40:17
【问题描述】:

我正在尝试使用下面提到的数据为 geom_line 图制作动画:

quarter       Total.Return   Investor
2009-03-30      4       A
2009-03-30      5       B
2009-06-30      7       A
2009-06-30     10       B
2009-09-30     12       A
2009-09-30     11       B
2009-12-30     25       A
2009-12-30     35       B
2010-03-30     65       A
2010-03-30     65       B

我的代码

library(ggplot2)
library(gganimate)
ggplot(newfile, aes(Quarter, Total.Return, color = Investor, label = Investor, group = Investor)) +
  geom_line()+
  scale_x_date(breaks = newfile$Quarter)+
  theme(axis.text.x = element_text(angle = 90, hjust = 1))
  # scale_x_date(labels = date_format("%m/%d/%Y"))+
  transition_time(Quarter)

【问题讨论】:

  • 我不知道您遇到了什么错误,但似乎命令 y = newfile$Total.Return 可能是个问题,因为该变量被简单地称为 Return
  • @mmyoung77 我得到 ggproto 对象错误变量不是问题

标签: r gganimate


【解决方案1】:

可能是我没有正确提出问题。但我能够让我的代码运行,所以发布答案:

   ggplot(newfile, aes(Date,  TotalReturn, color = Investor)) +
      geom_line(aes(size = 3)) +
      geom_point(aes(size = 6,alpha = 0.5)) +
      geom_text(aes(label=paste0(TotalReturn,"%")),hjust= -0.5, vjust=0,size = 6)+
      facet_grid(rows = vars(Investor)) +
      # theme(legend.position = 'none') +
      labs(title = 'Total Return, Quarter: {frame_along}') +
      theme(axis.title=element_text(face="bold.italic", 
                                        size="12", color="brown"), legend.position="none") +
      transition_reveal(along =Date) +
      ease_aes('linear')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2019-03-23
    相关资源
    最近更新 更多