[R] Date order question

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Thu Jan 5 08:06:34 CET 2023


Hallo Thomas

Similar as suggested by Rui, you shall change your date to real date e.g. by

library(lubridate)
date <- paste(date, c(rep(2022,2), 2023), sep="-")
date <- mdy(date)

and you need to change also x coordinate in annotate.

ggplot(data, aes(x=date,y=PT,group=1))+
  geom_point(size=4)+
  geom_line()+
  geom_hline(yintercept =c(1,.60,0,.30,.25,.2))+
 
scale_y_continuous(label=scales::label_percent(),breaks=c(1,0.6,0,.3,0.25,0.
2))+
  annotate("text", x=date[2], y=.1, label="Very
Good",size=5,fontface="bold")+
  annotate("text", x=date[2], y=.225, label="Good",size=5,fontface="bold")+
  annotate("text", x=date[2], y=.28,
label="Marginal",size=5,fontface="bold") +
  annotate("text", x=date[2], y=.45,
label="Inadequate",size=6,fontface="bold")+
  annotate("text", x=date[2], y=.8, label="OOC",size=6,fontface="bold")+
  annotate("text", x=date[2], y=-.05, label="PT Not
Done",size=5,fontface="bold")

Cheers
Petr

> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Thomas Subia
> Sent: Wednesday, January 4, 2023 10:08 PM
> To: r-help using r-project.org
> Subject: [R] Date order question
> 
> Colleagues,
> 
> date<-c("12-29","12-30","01-01")
> PT <- c(.106,.130,.121)
> data <- data.frame(date,PT)
> ggplot(data, aes(x=date,y=PT,group=1))+
>   geom_point(size=4)+
>   geom_line()+
>   geom_hline(yintercept =c(1,.60,0,.30,.25,.2))+
> 
>
scale_y_continuous(label=scales::label_percent(),breaks=c(1,0.6,0,.3,0.25,0.
2))
> +
>   annotate("text", x=2.5, y=.1, label="Very Good",size=5,fontface="bold")+
>   annotate("text", x=2.5, y=.225, label="Good",size=5,fontface="bold")+
>   annotate("text", x=2.5, y=.28, label="Marginal",size=5,fontface="bold")
+
>   annotate("text", x=2.5, y=.45,
label="Inadequate",size=6,fontface="bold")+
>   annotate("text", x=2.5, y=.8, label="OOC",size=6,fontface="bold")+
>   annotate("text", x=2.5, y=-.05, label="PT Not
Done",size=5,fontface="bold")+
>   theme_cowplot()
> 
> The plot has the wrong date order.
> What is desired is 12-29, 12-30 and 01-01.
> 
> Some feedback would be appreciated.
> 
> All the best,
> Thomas Subia
> 
> "De quoi devenir chevre? Des donnees"
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list