0

I wanted to plot a bar graph of monthly sales of 2 years with sales of the same month in both years appearing side by side. The following code returns the error

Error: Invalid input: date_trans works with objects of class Date only

What could have been my mistake?

 class(it_data$Invoice.Date)
    [1] "Date"
    head(it_data$Invoice.Date)
    [1] "2020-01-03" "2020-01-03" "2020-01-03" "2020-01-03" "2020-01-03"
    [6] "2020-01-03"
    #bar plot count of sales wrt month
    library(ggplot2)
    library(plyr)
    it_data$month<-strftime(it_data$Invoice.Date, "%b")
    it_data$year<-strftime(it_data$Invoice.Date, "%Y")
    timestamps_month = count(it_data, vars = c("month","year"))
    ggplot(data = timestamps_month) + 
      geom_bar(aes(x = month, y = freq, fill = year), stat="identity", position = "dodge")+
      scale_x_date(date_breaks = "months", date_labels = "%b %Y")
Richard Telford
  • 9,558
  • 6
  • 38
  • 51
Lakshmi
  • 1
  • 1

0 Answers0