Error: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class Date Error: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class Date r r

Error: `data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class Date


Try this:Workflow is as follows:

 library(tidyverse)    library(lubridate)    #`df` is `CPOD_Time` saved as `df<-as.data.frame(CPOD_Time)`    df<-as.data.frame(CPOD_Time)

Then the plot:

df %>%       rename(Time=time,Number=number,Date=date) %>%       mutate(Date=str_replace_all(Date,"\\D","-"),Date=as.character(Date),             Date=dmy(Date)) %>%     ggplot(aes(x=Date, y=Number, fill=Time)) +       geom_bar(stat="identity") +theme_bw() + geom_text(aes(label=Number), vjust=1.6,size=3.5)