Adding an annotation, receiving: time_trans error

Hi, I'm trying to add an annotation to a line graph, but I keep getting this error:

Error: Invalid input: time_trans works with objects of class POSIXct only

Quick fix anyone? I tried using as.date but no luck.

pacman::p_load('dplyr', 'tidyr',
               'ggplot2', 'ggalt',
               'forcats', 'R.utils', 'png',
               'grid', 'ggpubr', 'scales',
               'bbplot')

library(lubridate)

line_df <- COVID_ButteCounty_Master %>%
filter (D >= as.Date("2020-06-01") & D <= as.Date("2020-07-08"))

#Make plot
line <- ggplot(line_df, aes(x = D, y = Cases)) +
  geom_line(colour = "#8C2332", size = 2) +
  geom_hline(yintercept = 0, size = 1, colour="#333333")+
  geom_label(aes(x = 2020-07-08, y = 250, label = "295 cases"),+
             hjust = 0,
             vjust = 0.5,
             lineheight = 0.8,
             colour = "#555555",
             fill = "white",
             label.size = NA,
             family="Helvetica",
             size = 6)+
  bbc_style() +
  labs(title="COVID-19 in Butte County",
       subtitle="20 new cases; death toll rises to 4")
line

Use as.POSIXct()

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

1 Like

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

That worked. Thank you.

1 Like