[R] plotting variable sections of hourly time series data using plot.zoo
Jan.Schwanbeck at hydrologie.unibe.ch
Jan.Schwanbeck at hydrologie.unibe.ch
Thu May 31 15:54:13 CEST 2007
Dear list,
I have to look examine hourly time - series and would like to plot variable
section of them using plot.zoo.
Hourly time series data which looks like this:
YYYY MM DD HH P-uk P-kor P-SME EPOT EREA RO R1
R2 RGES S-SNO SI SSM SUZ SLZ
2003 1 1 1 0.385 0.456 0.021 0.000 0.000 0.000 0.013
0.223 0.235 0.01 0.38 74.72 0.96 736.51
2003 1 1 2 0.230 0.275 0.028 0.000 0.000 0.000 0.012
0.223 0.235 0.03 0.56 74.72 0.94 736.37
#With help of read.table I got the data into R :
DF <- read.table(file=fn,header=FALSE,skip=2)
#Substitute the header:
names(DF) <-
c("year","month","day","hour","FN","Punc","Pcor","Pmelt","ETP","ETR","RS","RI","RB","Rtot","Ssnow","SI","SSM","SUZ","SLZ")
#Create datetime vector
library(chron)
DF$datetime <- with(DF,chron(paste(month,day,year,sep="/"))+hour/24)
#Try to convert DF into ts - object DFts
DFts <- as.ts(DF) # works, but gives back: Warning message: Class
information of one or more columns was lost.???
#Try to convert DF into zoo - object DFzoo
library(zoo)
DFzoo <- as.zoo(DFts)
#Plot of whole time series skipping first 5 and last 3 columns
plot.zoo(DFzoo[ ,6:ncol(myDFzoo-3)])
# works, but x-axis labels are numbers from 1 to ...last hour
I would like to use plot.zoo for plotting:
- the whole period (3years) --> axis-labels month and year
- section of few days defining begin and end as date --> axis-label day
and month (may be hour)
Afer long tries with "as.Date" and Co. I still didn't get any useful
result.
Further is there any possibility to define the plot window using two
variables like:
begin <- "22/2/2003 01:00:00"
end <- "26/3/2003 07:00:00"
to plot the time series section in between this two dates?
I am even not sure if the zoo package was the right choise for my problem.
Thanks a lot in advance
Best regards
Jan
University of Berne
More information about the R-help
mailing list