[R] problems with xlim in plot.zoo() and window()
Agustin Lobo
Agustin.Lobo at ictja.csic.es
Tue May 29 17:47:35 CEST 2012
I'm trying to get a minimally intuitive way of plotting zoo objects
extracted for given periods of time
I do:
> plot(alyL32007z$NEE_st,col=cod,type="b",pch=18,xlim=time(alyL32007z)[c(3000,15000)])
and get a correct plot but the expression for xlim is hard to read by humans.
I try
> time(alyL32007z)[c(3000,15000)]
[1] "2007-03-04 11:30:00 UTC" "2007-11-09 11:30:00 UTC"
> plot(alyL32007z$NEE_st,col=cod,type="b",pch=18,xlim=c("2007-03-04 11:30:00 UTC" ,"2007-11-09 11:30:00 UTC"))
Error in plot.window(...) : invalid 'xlim' value
an error that makes sense, but then I try:
> as.Date(c("2007-03-04 11:30:00 UTC" ,"2007-11-09 11:30:00 UTC"))
[1] "2007-03-04" "2007-11-09"
> plot(alyL32007z$NEE_st,col=cod,type="b",pch=18,xlim=as.Date(c("2007-03-04 11:30:00 UTC" ,"2007-11-09 11:30:00 UTC")))
and get no error but an empty plot.
How can I set xlim using a simple expression for given dates?
I've also tried with window(), but:
> delme <- window(alyL32007z, start = as.Date("2007-03-04"),end=as.Date("2007-11-09"))
Warning messages:
1: In which(in.index & all.indexes >= start & all.indexes <= end) :
Incompatible methods ("Ops.POSIXt", "Ops.Date") for ">="
2: In which(in.index & all.indexes >= start & all.indexes <= end) :
Incompatible methods ("Ops.POSIXt", "Ops.Date") for "<="
> str(delme)
‘zoo’ series (without observations)
> delme <- window(alyL32007z, start = c(2007, 3), end = c(2007, 12))
> str(delme)
‘zoo’ series (without observations)
Is this a problem with the way I've made the dates? (using as.POSIXct())
Data in http://dl.dropbox.com/u/3180464/alyL32007z.rda
http://dl.dropbox.com/u/3180464/alyL32007.rda
alyL32007z <- zoo(alyL32007[-1],alyL32007$time)
Agus
--
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
Lluis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
e-mail Agustin.Lobo at ictja.csic.es
https://sites.google.com/site/aloboaleu/
More information about the R-help
mailing list