ローマンの助けに感謝します。これが私たちが最終的に行った方法です。
flow<-read.table("iv.txt",comment.char="#",header=TRUE)
Q<-as.data.frame(c(0,(60*diff(flow$wt,1,1)/0.5))) # Q is used for flow in the standard
names(Q)<-"Q"
# Now combine them
l<-list(flow,Q)
dflow<-as.data.frame(l)
t1flow<-subset(dflow, dflow$secs>60*60 & dflow$secs<=120*60) # require the second hour of the data
t1flow$QE<-((t1flow$Q-setflow)/setflow)*100 # calculate the error
library(TTR) # use this for moving averages
#
# Avert your eyes! I know there must be a slicker way of doing this .....
#
# Calculate the moving average using a sample rate of every 4 readings (2 mins of 30sec readings)
QE2<-SMA(t1flow$QE,4)
minQE2<-min(QE2,na.rm=TRUE)
maxQE2<-max(QE2,na.rm=TRUE)
# now for the 5 minute window
QE5<-SMA(t1flow$QE,10)
minQE5<-min(QE5,na.rm=TRUE)
maxQE5<-max(QE5,na.rm=TRUE)
# Set window to 11 mins
QE11<-SMA(t1flow$QE,22)
minQE11<-min(QE11,na.rm=TRUE)
maxQE11<-max(QE11,na.rm=TRUE)
# Set window to 19 mins
QE19<-SMA(t1flow$QE,38)
minQE19<-min(QE19,na.rm=TRUE)
maxQE19<-max(QE19,na.rm=TRUE)
# Set window to 31 mins
QE31<-SMA(t1flow$QE,62)
minQE31<-min(QE31,na.rm=TRUE)
maxQE31<-max(QE31,na.rm=TRUE)
#
# OK - you can look again :-)
#
# create a data frame from this data
trump<-data.frame(c(2,5,11,19,31),c(minQE2,minQE5,minQE11,minQE19,minQE31),c(maxQE2,maxQE5,maxQE11,maxQE19,maxQE31))
names(trump)<-c("T","minE","maxE")
A<-mean(t1flow$QE) # calculate the overall mean percentage error
error_caption<-paste("overall percentage error = ",A,"%") # create the string to label the error line
# plot the graph
ggplot(trump, aes(x = T, y = minE)) +
geom_line() +
geom_point(color="red") +
geom_line(aes(y = maxE)) +
geom_point(aes(y = maxE),colour="red") +
geom_hline(aes(yintercept = 0), linetype = "dashed") + # overall percentage error
geom_hline(aes(yintercept = A), linetype = "solid") + # set rate
xlab("Observation windows (in minutes)") +
ylab("% error") +
scale_x_continuous(breaks=c(0,2,5,11,19,31),limits=c(0,32)) + # label the x axis only at the window values
annotate("text", x = 10, y = A-0.5, label = error_caption) + # add the error line label
opts(title="Trumpet curve for Test Data")

また利用可能ですh最終的なグラフを見ることができます[ここ][2]