0

I m trying to animate geom_line graph with below mentioned data :

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

My code

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)
markus
  • 25,843
  • 5
  • 39
  • 58
gurtej
  • 13
  • 5
  • I don't know what error you're getting, but it seems like the command `y = newfile$Total.Return` could be a problem, since the variable is simply called `Return`. – mmyoung77 Jan 30 '19 at 20:44
  • @mmyoung77 I am getting ggproto object error variable is not a problem – gurtej Jan 30 '19 at 20:46

1 Answers1

0

May be I didn't put question correctly. But I able to make my code run so posting answer :

   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')
gurtej
  • 13
  • 5