【发布时间】:2021-03-11 08:10:16
【问题描述】:
value<-c(2,4,5,6,7,8,9,8,7,7,7,2,1,4,1,14,44,34,33,66,7,87,99,90,45,69,77,0,65,2)
LSL<-80
DateTime<-c("2020-11-24 15:59:22 GMT", "2020-11-24 16:29:22 GMT", "2020-11-25 08:02:36 GMT",
"2020-11-27 08:27:58 GMT", "2020-11-27 08:57:58 GMT", "2020-11-27 09:27:58 GMT",
"2020-11-27 09:57:58 GMT" ,"2020-11-27 10:27:58 GMT", "2020-11-27 10:57:58 GMT",
"2020-11-27 11:27:58 GMT", "2020-11-27 11:57:58 GMT" ,"2020-11-27 12:27:58 GMT",
"2020-11-27 12:57:58 GMT" ,"2020-11-27 13:27:58 GMT", "2020-11-27 13:57:58 GMT",
"2020-11-27 14:27:58 GMT" ,"2020-11-27 14:57:58 GMT" ,"2020-11-27 15:27:58 GMT",
"2020-11-27 15:57:58 GMT" ,"2020-11-27 16:27:58 GMT" ,"2020-11-27 16:57:58 GMT",
"2020-11-27 17:27:58 GMT", "2020-11-27 17:57:58 GMT", "2020-11-27 18:27:58 GMT",
"2020-12-20 06:36:38 GMT", "2020-12-20 07:06:38 GMT" ,"2020-12-20 07:36:38 GMT",
"2020-12-20 08:06:38 GMT" ,"2020-12-20 08:36:38 GMT" ,"2020-12-20 09:06:38 GMT")
DateTime<-as.POSIXct(DateTime)
Group<- c("Hungry","Hungry","Hungry","Hungry","Laughing","Laughing","Laughing","Laughing","Hungry","Hungry","Angry","Angry","Angry","Angry","Laughing","Laughing","Laughing","Laughing","Happy","Happy","Happy","Happy","Angry","Angry","Angry","Angry","Laughing","Laughing","Laughing","Laughing")
DATA<-data.frame(cbind(DateTime,value,Group))
DATA$Months<-months(DateTime,abbreviate=F)
idx <- c(0, diff(as.numeric(DATA$DateTime)))/60
i2 <- c(1,which(idx >30), nrow(DATA)+1)
DATA$grp <- rep(1:length(diff(i2)), diff(i2))
jpeg("TEST.jpg", width=8000, height=4000, res=300)
ggplot(DATA,aes(x=DateTime,y=value)) +
geom_line(aes(group=grp))+
geom_point(aes(colour=Value<LSL))+
scale_colour_manual(name="value<LSL",values=setNames(c('red','black'),c(T,F)))+
geom_hline(aes(yintercept=LSL,linetype="Lower Specification Limit"), color = "red")+
scale_linetype_manual(name = "Specification Limits",values = c("solid"),guide=guide_legend(list(color
= c("Specification Limits"))))+
labs(x = "Dates",
y = "value",
title = "Value Out Of Specifications ") +
scale_x_datetime(date_labels = "%a-%d", date_breaks ="1 day",
sec.axis = dup_axis(name="Hours",labels = scales::time_format("%H:%M"),breaks
=scales::date_breaks("5 hours")))+
facet_wrap(~ Months,scales = "free")+
theme(axis.text.x = element_text( angle = 90, vjust = 1, hjust=1))
dev.off()
这是我未运行的代码,我试图运行它,但总是给我这个错误
Error: Invalid input: time_trans works with objects of class POSIXct only
嗯,我试图解决这个问题,但我做不到。这是运行它的任何方式吗?如果可能的话,我还希望将要打印的行由 Group 变量着色(一行多种颜色)提前谢谢你。
【问题讨论】: