[R] 24 hour axis /time plots

Jim Lemon jim at bitwrit.com.au
Sat Feb 21 12:20:36 CET 2009


somewhereondearth wrote:
> Hi, 
> i have a data with values against  time and date. for plotting against date
> i used axis.Date() option. but I need a 24hr time plot as well. i have
> extracted and plotted, but not being able to put the time ticks ( eg. 6am, 7
> am etc) on the x-axis. Im new to R, any help would be appreciated!!
>   
Hi somewhereondearth,
I would suggest that you convert your hours into military time 
(0000-2359) and then plot the data without an X axis (xaxt="n"). Then 
add the X axis with the appropriate 12 hour labels:

hr12labels<-c("12AM","2AM",...,"10PM")
axis(1,at=seq(0,2400,by=200),labels=hr12labels)

You can do this with date/time variables, but for a one-off, it may be 
easier to just define the labels you want yourself.

Jim




More information about the R-help mailing list