[R] problems with xlim in plot.zoo() and window()

Agustin Lobo Agustin.Lobo at ictja.csic.es
Tue May 29 19:39:36 CEST 2012


Thanks!
Using as.POSIXct() instead of as.Date() solves the problem:
> plot(alyL32007z$NEE_st,col=cod,type="b",pch=18,xlim=as.POSIXct(c("2007-03-04 11:30:00 UTC" ,"2007-11-09 11:30:00 UTC"))) #works fine
> delme <- window(alyL32007z, start = as.POSIXct("2007-03-04",tz="UTC"),end=as.POSIXct("2007-11-09",tz="UTC"))
> str(delme)
‘zoo’ series from 2007-03-04 to 2007-11-09
  Data: num [1:12001, 1:38] 3 3 3 3 3 3 3 3 3 3 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:38] "Month" "Day" "Hour" "doy2" ...
  Index:  POSIXct[1:12001], format: "2007-03-04 00:00:00" "2007-03-04
00:30:00" "2007-03-04 01:00:00" "2007-03-04 01:30:00" "2007-03-04
02:00:00" "2007-03-04 02:30:00" ...

Would you advice in favor of using Date objects instead of POSIXct ?

Agus

On Tue, May 29, 2012 at 7:13 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Tue, May 29, 2012 at 11:47 AM, Agustin Lobo
> <Agustin.Lobo at ictja.csic.es> wrote:
>> 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)
>
> The code is attempting to use Date class with a series whose index is
> not of Date class.
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com



-- 
--
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