[R] format secondary axis for dates
David Winsemius
dwinsemius at comcast.net
Tue Nov 16 21:06:33 CET 2010
On Nov 16, 2010, at 2:32 PM, Jannis wrote:
> Dear List,
>
>
> this may be a Newbi question and may have been asked several times,
> but i am too stupid to find the posts.
>
>
> I have a plot of values against POSIXct time steps. If I want to add
> a second x axis to the top margin of the plot, only numbers are at
> the tickmarks. Is there a straightforward way to specify the format
> to convert them to character representations (similar to the labels
> at the bottom)?
>
> x<-as.POSIXct(1:1000*(60^2),origin='01-01-1970')
The origin argument was incorrect and you got the wrong starting point:
> x[1]
[1] "0001-01-19 01:00:00 EST"
> y=rnorm(1000)
> plot(x,y)
> axis(3)
This gives ticks at hourly intervals:
axis(3, labels=format(x, "%Y-%m-%d"), at=x)
Whereas this is probably what you want (after correcting the origin to
"1970-01-01"
axis.POSIXct(3, x=x, labels=TRUE )
--
David.
>
>
> Thanks for your help
> Jannis
>
>
>
>
>
> ______________________________________________
> 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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list