[R] Date on x-axis of xyplot

Heywood, Giles Giles.Heywood at CommerzbankIB.com
Tue Sep 23 13:15:45 CEST 2003


One thing you could do is to use the 'its' (irregular time-series) 
package on CRAN.

e.g. using a trivial dataset

require(its)
its.format("%Y-%m-%d") #defines text format of dates in dimnames
df <- data.frame(1:3,(1:3)^2)
dimnames(df) <- list(c("2003-01-03","2003-01-06","2003-01-07"),letters[1:2])
plot(its(as.matrix(df)),type="p")

or more simply

mat <-
structure(1:6,dim=c(3,2),dimnames=list(c("2003-01-03","2003-01-06","2003-01-
07"),letters[1:2]))
plot(its(mat),type="p")

Clearly plot does not provide the same functionality as the 
beautifully crafted xyplot of lattice, but dates do get handled
as an abcissa. Incidentally the implementation of 'its' uses the 
POSIXct class, but this is largely encapsulated.

Giles

> -----Original Message-----
> From: Charles H. Franklin [mailto:franklin at polisci.wisc.edu]
> Sent: 17 September 2003 04:00
> To: r-help at stat.math.ethz.ch
> Subject: [R] Date on x-axis of xyplot
> 
> 
> xyplot doesn't seem to want to label my x-axis with dates but 
> instead puts
> the day-number for each date.
> 
> begdate is the number of days since January 1, 1960 and was initially
> created by
> 
> library(date)
> 
> ...
> 
> polls$begdate<-mdy.date(begmm,begdd,begyy)
> 
> I create a new dataframe (pollstack) which includes begdate. 
> In the process
> begdate seems to lose its date attribute so I redo it as:
> 
> > pollstack$begdate<-as.date(pollstack$begdate)
> 
> after which
> 
> > attach(pollstack)
> > summary(pollstack)
>    begdate               pct              names
>  First :15Nov2002   Min.   : 0.000   Clark   : 54
>  Last  :10Sep2003   1st Qu.: 2.000   Dean    : 54
>                     Median : 5.000   Edwards : 54
>                     Mean   : 6.991   Gephardt: 54
>                     3rd Qu.:12.000   Graham  : 54
>                     Max.   :29.000   Kerry   : 54
>                                      (Other) :216
> >
> 
> And all seems well.
> 
> But xyplot continues to use day number on the x-axis. My 
> plots are created
> by
> 
>  print(xyplot(pct ~ begdate | names, pch=2, cex=.2,
>    prepanel = function(x, y) prepanel.loess(x, y, span = 1),
>    main="2004 Democratic Primary Race",
>    xlab = "Date of Survey",
>    ylab = "Percent Support",
>    panel = function(x, y) {
>        panel.grid(h=-1, v= -1)
>        panel.xyplot(x, y, pch=1,col=2,cex=.7)
>        panel.loess(x,y, span=.65, lwd=2,col=4)
>       }, ) )
> 
> What am I missing?
> 
> Thanks!
> 
> Charles
> 
> 
> 
> /******************************************
> ** Charles H. Franklin
> ** Professor, Political Science
> ** University of Wisconsin, Madison
> ** 1050 Bascom Mall
> ** Madison, WI 53706
> ** 608-263-2022 Office
> ** 608-265-2663 Fax
> ** mailto:franklin at polisci.wisc.edu (best)
> ** mailto:chfrankl at facstaff.wisc.edu (alt)
> ** http://www.polisci.wisc.edu/~franklin
> ******************************************/
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 


********************************************************************** 
This is a commercial communication from Commerzbank AG.\ \ T...{{dropped}}




More information about the R-help mailing list