I have this piece of code.
My goal is plot data for the last month.
I read on the web that it is possible with scale_x_date(limits = as.Date
So 1st step I tried plot data in specified timeframe... e.g. 2020-05-01","2020-09-09
but when I insert this code to my ggplot I got this error
Invalid input: date_trans works with objects of class Date only
Any idea what is wrong ?
Dataframe example: read from csv
"date","diff"
2020-01-22,555
2020-01-23,99
2020-01-24,287
2020-01-25,493
...
Code:
##before plot I had to convert date from posix time, to show properly date in plot
conf_all_data$date <- as.POSIXct(conf_all_data$date)
##ggplot
ggplot(conf_all_data, aes(x=date, y=diff, text=paste(date, "\n" , "Confirmed:", diff ))) +
geom_bar(stat='identity',fill='blue') +
scale_x_date(limits = as.Date(c("2020-05-01","2020-09-09"))) +
scale_y_continuous(labels = comma),
tooltip = "text"
One comment added here:
If date is not date as it looks like, why then ggplot has no problem with correct plotting this chart also with X date Axis ?
You can check my working site here http://webcovid19.online/, code is in all charts the same, only I removed problematic part with scale_x_date,
I have added also screenshot

Thanks to all, issue was really wrong Date type, when I did debug in console, I realized that after read csv to DF is factor type, then I have to convert with As.date()
Anyway my question is if I want show plot of last month period dataframe, e.g. today we have 2020-12-08, Is there some Date function with arithmetic operations to get minus 30 days ( or another number) from today to deal with months crossing ?
Here is my working screenshot with specified working timeframe
ggplot(slovakia_conf_inc, aes(x=date, y=confirmed, text=paste( date, "\n", "confirmed:", confirmed ))) +
geom_bar(stat='identity',fill='blue') +
scale_x_date(breaks = "1 month") +
scale_x_date(limits = as.Date(c("2020-08-01","2020-09-09"))) +
scale_y_continuous(labels = comma),
tooltip = "text"



