Date_Trans Error when adding annotate label

I have a ggplot that creates a line graph based on some time series data, however when I am trying to add a annotate label I receive the error

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

I don't understand this error as I haven't changed any of my classes or graph, just added a text box.

  annotate("text", x = 2020-05-21, y = 0.05, label = "Current CFR Date _____: _______")

Here is the script I am using to create my ggplot

sapply(results$Date, typeof)

results$Date <- ymd(results$Date)

ggplot(results, aes(x = results$Date, y = results$CFR_Calculation)) + 
  scale_x_date(breaks = seq.Date(from = as.Date("2020-03-07"), 
                                 to = as.Date("2020-06-25"), by = 25)) +
  geom_line() +
  labs(x = "Date (In 25 Day Interval)", y = "CFR Calculation") + 
  ggtitle("Case Fatality Rate in Canada") + 
  annotate("text", x = 2020-05-21, y = 0.05, label = "Current CFR Date _____: _______")

I can't test this since you are not providing a reprex but I think you just have to use as.Date()

annotate("text", x = as.Date("2020-05-21"), y = 0.05, label = "Current CFR Date _____: _______")

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.