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/
Gabor Grothendieck
2012-May-29 17:13 UTC
[R] problems with xlim in plot.zoo() and window()
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
Possibly Parallel Threads
- zoo: variable gets modified at making zoo object
- Date_Time detected as Duplicated (but they are not!)
- Problems creating a PNG file for a dendrogram: "Error in plot.window(...) : need finite 'xlim' values"
- summary() and range(): inconsistency?
- blazer_usb MEC0002 problem Fry's Electronics (Turbo-X)