My x axis is date, how do I draw vertical arrows pointing to specific dates?

40 views Asked by At

I have created a data frame ('precip2') with 'Date' and precipitaion ('sum_precip'). I have created a bar chart in ggplot which shows precipitation on particular dates. I want to now draw vertical arrows above the bar, pointing to specific dates.

I get the error message: 'Error: Invalid input: date_trans works with objects of class Date only'

im pretty sure the Date is of the class date

Thanks

This is what I have so far:

    precip2 %\>%
    ggplot(aes(x=Date,y=sum_precip))+
    geom_bar(stat="identity",fill="blue")+
    theme(
    panel.background=element_rect(fill="white"),
    axis.line=element_line(colour="black")) +
    geom_segment(aes(x= 2017-11-22, y = 60 , xend = 2017-11-22, yend = 30))

im pretty sure the Date is of the class date as I put this in the script before:

precip2$Datetime\<-as.POSIXct(precip2$Datetime,"%d/%m/%Y %H:%M",tz="UTC")
1

There are 1 answers

0
JudgedGem On
precip2 %\>%
    ggplot(aes(x=Date,y=sum_precip))+
    geom_bar(stat="identity",fill="blue")+
    theme(
    panel.background=element_rect(fill="white"),
    axis.line=element_line(colour="black")) +
    geom_segment(aes(x= as.Date("2017-11-22"), 
                     y = 60 , 
                     xend = as.Date("2017-11-22"), 
                     yend = 30))

Without seeing the format of precip2, I think this should work.