[R] Date on x-axis of xyplot

Charles H. Franklin franklin at polisci.wisc.edu
Wed Sep 17 05:00:10 CEST 2003


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
******************************************/




More information about the R-help mailing list