我想做的事情:
在我的“工作日”列表中创建了一个没有下雨的情节,绘制了超级强加。 (一个x轴和y轴点的散点图)
绘制一条平均曲线,代表所有工作日的水文图,在观察到的时间内没有下雨!
这是我的最终解决方案(我认为代码太复杂了,但它有效:
#create list of data frames splitted by days
daysplit<-split.default(data_regression_PCM4 [,1], format(index(data_regression_PCM4), "%a"))
#create a list for each day of the week
Monday<-list(daysplit$Mo)
#create a list "Monday" splitted by date
Monday<-as.data.frame(Monday)
Monday [,2]<-row.names(Monday)
Monday[,2]<-as.POSIXct(Monday[,2], format="%Y-%m-%d %H:%M:%S", tz="UTC")
Monday <- xts(Monday[,-2], order.by=Monday[,2])
Monday<-split(Monday, "days")
#Monday without rain (flow rate less than 20 L/s)
cond <- lapply(Monday, function(x) max(x) < 20)
Monday_TW<-Monday[unlist(cond)] #Monday "No rain"
#convert lists of xts to lists of df
Monday_TW <- lapply(Monday_TW, function(x) data.frame(DateTime=index(x),Abfluss=coredata(x)))
#Extract lists to data frames while omitting the DateTime column
mo<-lapply(Monday_TW, function(x) x[!(names(x) %in% c("DateTime"))])
mo <- do.call(cbind,mo)
#combine all weekdays to one df
weekdays_TW<-cbind(mo,di,mi,do,fr)
weekdays_TW [,11]<-(seq(as.POSIXct("2014-12-29 00:00:00",tz="UTC"), as.POSIXct("2014-12-29 23:55:00",tz="UTC"),by="5 min"))#add Time column with random date (only time matters)
names(weekdays_TW)<-c("Abfluss_1","Abfluss_2","Abfluss_3","Abfluss_4","Abfluss_5","Abfluss_6","Abfluss_7","Abfluss_8","Abfluss_9","Abfluss_10","Time")
weekdays_TW<-weekdays_TW[c(11,1,2,3,4,5,6,7,8,9,10)]
#melt df
melted_TW <- melt(weekdays_TW , id = 'Time', value_name = 'series')
names(melted_TW)<-c("Time","values","Abfluss")
##Plot via ggplot2
TW_plot<-ggplot(melted_TW, aes(Time,Abfluss)) + geom_point(aes(color = values))
TW_plot+stat_smooth(method = "lm", formula = y ~ poly(x, 9), size = 1,se=F)+
scale_x_datetime( breaks=("2 hour"),minor_breaks=("1 hour"),labels=date_format("%H:%M")) +
xlab("Time [h]")+ ylab("Abfluss Q [L/s]") +
"Montag_2", "Dienstag_1", "Dienstag_2","Mittwoch_1","Mittwoch_2","Donnerstag_1","Donnerstag_2","Freitag_1","Freitag_2"))+ labs(title="Tagesgang PCM4 / Wochentage") +
theme(plot.title = element_text(lineheight=.8, face="bold"))
结果情节:
这是我使用的数据样本:
DateTime Q (L/s)
2015-01-26 00:00:00 12.057333
2015-01-26 00:15:00 13.137333
2015-01-26 00:30:00 12.639000
2015-01-26 00:45:00 12.476333
这是我使用的数据集:
http://m.uploadedit.com/ba3d/1432744791634.TXT
如果有人碰巧找到了一个更简单的解决方案,我将不胜感激!