[R] format secondary axis for dates

Jannis bt_jannis at yahoo.de
Thu Nov 18 15:16:48 CET 2010


Thanks for your help, David! Somehow I just could not find this 
information in the documentation!


Jannis


David Winsemius schrieb:
>
> 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 )
>



More information about the R-help mailing list