发行带有日期与价值的动画以及带有gganimate的投资者的动画

时间:2019-01-30 20:40:18

标签: r gganimate

我正在尝试使用以下提到的数据为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)

1 个答案:

答案 0 :(得分:0)

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

   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')