[R] plotting variable sections of hourly time series data using plot.zoo

Gabor Grothendieck ggrothendieck at gmail.com
Thu May 31 16:38:56 CEST 2007


Regarding your other questions:


plot(z[,3:5]) # only plot columns 3 to 5

# only plot between indicated times
st <- chron("01/01/03", "02:00:00")
en <- chron("03/26/2003", "07:00:00")
zz <- window(z, start = st, end = en)
plot(zz)




On 5/31/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> There seems to be an error in your names(DF) <- line so I just renamed the
> first 4 fields.  Try this:
>
> # Should be 3 lines in Lines.
> Lines <- "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
> "
> DF <- read.table(textConnection(Lines), header = TRUE)
> names(DF)[1:4] <- c("year", "month", "day", "hour")
> library(chron)
> library(zoo)
> z <- zoo(as.matrix(DF), with(DF,chron(paste(month,day,year,sep="/"))+hour/24))
> as.ts(z)
>
>
> On 5/31/07, Jan.Schwanbeck at hydrologie.unibe.ch
> <Jan.Schwanbeck at hydrologie.unibe.ch> wrote:
> >
> > 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
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > 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