[R-SIG-Finance] How to use zooreg and zoo in same plot?
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Apr 19 15:16:04 CEST 2010
Note that if you run this you do get a message telling you precisely
what is wrong:
Warning message:
In merge.zoo(..., all = all, fill = fill, suffixes = suffixes,
retclass = "zoo") :
Index vectors are of different classes: Date numeric
Try making them all Date class:
time(z) <- as.Date(as.yearmon(time(z)))
time(y) <- as.Date(as.yearqtr(time(y)))
plot(na.approx(cbind(x, y, z)))
On Mon, Apr 19, 2010 at 8:49 AM, Matthieu Stigler
<matthieu.stigler at gmail.com> wrote:
> Hi
>
> I'm having problems showing two time series in a plot, when one is of class
> zoo and the other one zooreg. I searched but did not find mention of this
> problem... do I do something wrong? How can I solve this? Thanks a lot!!
>
> x.date <- as.Date(paste(2004, rep(1:12, each=8),
> rep(c(1,4,8,12,16,20,25,28),6), sep = "-"))
> x <- zoo(rnorm(96), x.date)
> z<-zooreg(runif(12), start=c(2004,1), freq=12)
> y<-zooreg(runif(4), start=c(2004,1), freq=4)
>
> #try different plot methods:
> plot(cbind(x,z)) #does not work
> plot(cbind(y,z)) #show only z, probably because of point 9 in zoo-FAQ?
> plot(cbind(y,z), type="p") #then works!
>
> plot(x)
> lines(z,col=2) #z not ploted
> points(z,col=2) #z not ploted
>
> plot(z)
> lines(y,col=2) #work!
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>
More information about the R-SIG-Finance
mailing list