答复: [R] How to draw x-axis time label.

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Oct 18 12:18:01 CEST 2004


On Mon, 18 Oct 2004, Ivy_Li wrote:

> Thank you for helping me!
> I try the "pretty" funtion to select the x-axis position value.Then I use the "format" funtion.
> 
> xax.pos <- pretty(as.numeric(x$x.name))
> format(xax.pos,'%d %b %y')
> > xax.pos
> [1] 1091600000 1091800000 1092000000 1092200000 1092400000 1092600000 1092800000
> [8] 1093000000
> 
> There are something wrong. I found the xax.pos has been changed to the
> number of second calculated since 1970 ,such as 1091600000. So this
> problem was not solved.

The problem is that _you_ changed this by the use of as.numeric.  Why are 
you changing a time to a number by as.numeric?  And why are you calling a 
time `name' -- it is rather confusing!

If you didn't do that, you would find that plot() by default does 
sensible things, and calling axis.POSIXct will give you added control.  
See its help page.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list