Walt,
A few points.
as.numeric on a timeDate object will cast it to a vector of julian times
(seconds since 1/1/1960 IIRC).
xdf <- data.frame(list(
quarter=rep(rep(1:4,4),4),
year=rep(rep(2005:2008,each=4),4),
count=sample(1:100,64),
category=rep(LETTERS[1:4],each=16)
))
xdf$DATE <- timeDate(paste(3*(xdf$quarter-1)+1,xdf$year,sep=":"),
in.format="%m:%Y")
xyplot( count ~ as.numeric(DATE) | category,
data=xdf, layout=c(2,2), xlab="Date"
)
Makes xyplot happy, but the x-axis labels on each plot will be numbers
('14501') instead of dates. This can be fixed, but not without hacking lots
of Trellis code AFAIK.
Better is to split your data frame by category, build timeSeries objects,
then use trellisPlot.timeSeries:
xdf.catA <- xdf[xdf$category=="A",]
xdf.catB <- xdf[xdf$category=="B",]
xdf.catC <- xdf[xdf$category=="C",]
xdf.catD <- xdf[xdf$category=="D",]
xdf.catA.ts <- timeSeries(xdf.catA$count, positions=xdf.catA$DATE)
xdf.catB.ts <- timeSeries(xdf.catB$count, positions=xdf.catA$DATE)
xdf.catC.ts <- timeSeries(xdf.catC$count, positions=xdf.catA$DATE)
xdf.catD.ts <- timeSeries(xdf.catD$count, positions=xdf.catA$DATE)
trellisPlot.timeSeries(
list("A"=xdf.catA.ts, "B"=xdf.catB.ts, "C"=xdf.catC.ts,
"D"=xdf.catD.ts),
layout=c(2,2)
)
You can then customize the plot as you see fit (e.g., remove the grid
lines).
HTH,
Chris Green
________________________________
Christopher G. Green (cggreen AT stat.washington.edu),
Doctoral Candidate,
Department of Statistics, Box 354322, Seattle, WA, 98195-4322, U.S.A.
http://www.stat.washington.edu/people/cggreen/
> -----Original Message-----
> From: s-news-owner@lists.biostat.wustl.edu
> [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of
> Data Analytics Corp.
> Sent: Tuesday, July 01, 2008 7:32 AM
> To: s-news@lists.biostat.wustl.edu
> Subject: [S] Plotting time series in an xyplot
>
> Good morning,
>
> I have a data frame with four variables: quarter, year, count
> of delays in a category, the category label. There are four
> categories (A, B, C, and D), four years (2005 - 2008), and
> four quarters per year, so there are 64 rows. Some data may
> look like:
>
> quarter year count category
> 1 2005 10 A
> 2 2005 5 A
> 3 2005 12 A
> 4 2005 8 A
> ...
> 4 2008 1 D
>
> I want to create a four panel chart (one panel for each
> category) with the quarter/year on the x-axis as a time
> series and the count on the vertical of each panel. XYPLOT
> only allows (as far as I can tell), two numerics for
> plotting. But I want time on the x-axis. The function
> plot.timeSeries creates the type of chart I want, but not in
> a panel.
> How can I create my panel chart? Any advise? I would like
> something like xyplot(timeSeries(x) ~ count | category, data = x).
>
> I'm using S+ 8 on Windows Vista.
>
> Thanks,
>
> Walt
>
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> dataanalytics@earthlink.net
> www.dataanalyticscorp.com
>
> --------------------------------------------------------------------
> This message was distributed by
> s-news@lists.biostat.wustl.edu. To unsubscribe send e-mail
> to s-news-request@lists.biostat.wustl.edu with the BODY of
> the message: unsubscribe s-news
>
|