[R] Multiple time series plots

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jul 2 21:37:02 CEST 2008


Incompatability?  zoo can work with any date/time class that supports
certain methods and such methods have specifically been written
for fCalendar's timeDate class.  In fact there is a section in
vignette("zoo") on the timeDate class.

Also we can readily convert between fSeries' timeSeries class and
zoo and the xts package provides a class, xts, which further supports
this.

Here is some sample code:

library(fCalendar)
dts <- c("1989-09-28", "2001-01-15", "2004-08-30", "1990-02-09")
tms <- c(  "23:12:55",   "10:34:02",   "08:30:00",   "11:18:23")
td <- timeDate(paste(dts, tms), format = "%Y-%m-%d %H:%M:%S")

library(zoo)
z <- zoo(1:4, td)
zz <- merge(z, lag(z))
plot(zz)

library(fCalendar)
zz
as.timeSeries(zz)
as.zoo(as.timeSeries(zz))

On Wed, Jul 2, 2008 at 1:26 PM, Kerpel, John <John.Kerpel at infores.com> wrote:
> Stephen:
>
> That works great - thanks!  I have to admit it gets a little frustrating
> having to switch back and forth between packages because of
> cross-package incompatibility, but hey, more functionality = good.
>
> Best,
>
>
>
> john
>
>
>
> ________________________________
>
> From: stephen sefick [mailto:ssefick at gmail.com]
> Sent: Wednesday, July 02, 2008 11:57 AM
> To: Kerpel, John
> Cc: r-help at r-project.org
> Subject: Re: [R] Multiple time series plots
>
>
>
> have you tried package(zoo) it works very well and should do what you
> want
>
> On Wed, Jul 2, 2008 at 10:54 AM, Kerpel, John <John.Kerpel at infores.com>
> wrote:
>
> Hi all:
>
>
>
> I'm trying to plot two time series created in Rmetrics and label the
> x-axis with dates.  I tried the following:
>
>
>
> dates <- as.Date(seriesPositions(x.agg))
>
>
>
> r <- as.Date(range(dates))
>
>
>
> ts.plot(x.agg at Data[,c(1,5)],gpars=list(ylab="Volume",
> lty=c(1:2),xaxt="n",main="Plot of Volume"))
>
>
>
> axis.Date(1, at=seq(r[1], r[2], length.out=10),
> format="%Y-%m-%d",cex.axis=.75)
>
>
>
> legend("bottomleft",legend=c("Base Volume","Model Base
> Volume"),lty=c(1,2),inset=.01,cex=.5,adj=0)
>
>
>
> All this works fine, except I don't get the dates on the x-axis like I
> want.  When I try to plot a single series using "plot" it works as
> expected.
>
>
>
> Any advice?
>
>
>
> John
>
>
>       [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
>
>
>
> --
> Let's not spend our time and resources thinking about things that are so
> little or so large that all they really do for us is puff us up and make
> us feel like gods. We are mammals, and have not exhausted the annoying
> little problems of being mammals.
>
> -K. Mullis
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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