1

I have the following data:

df <- structure(list(Date = structure(c(5L, 6L, 7L, 8L, 9L, 10L, 11L, 
1L, 2L, 3L, 4L), .Label = c("01-Apr", "02-Apr", "03-Apr", "04-Apr", 
"25-Mar", "26-Mar", "27-Mar", "28-Mar", "29-Mar", "30-Mar", "31-Mar"
), class = "factor"), New = c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
9L, 0L, 6L)), class = "data.frame", row.names = c(NA, -11L))

This is my current code:

df$Date<-as.character(df$Date)
df$Date <- factor(df$Date, levels=unique(df$Date))

p <- ggplot(data=df, aes(x=Date, y=New, group=1)) + 
        geom_line() + 
        theme_classic() + 
        theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) +
        xlab("Date") +ylab("Total")+theme(axis.text.x=element_text(size=5))

I'm looking to use gganimate to animate the graph, but when I use the code

p+transition_reveal(Date)

I get the error

Error: along data must either be integer, numeric, POSIXct, Date, difftime, orhms
In addition: Warning message:
In min(cl[cl != 0]) : no non-missing arguments to min; returning Inf

Suggestions?

Trying to make something like the geom_line plots from https://www.datanovia.com/en/blog/gganimate-how-to-create-plots-with-beautiful-animation-in-r/

M--
  • 25,431
  • 8
  • 61
  • 93
lst22
  • 97
  • 7
  • 1
    You should provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). What is `Total.Cases`? You also need to provide more details on what exactly it is that you are trying to do. – M-- Mar 13 '20 at 20:36
  • Apologies, please see the updated question. I am simply trying to animate the graph using the transition_reveal(Date) function. – lst22 Mar 13 '20 at 20:41
  • 2
    You first need to transform the date from string to Date `df$Date<-as.Date(df$Date, format="%d-%b")` – HubertL Mar 13 '20 at 20:44
  • That worked. Thank you! – lst22 Mar 13 '20 at 21:15

0 Answers0