[R] x axis labelling

Duncan Mackay dulcalma at bigpond.com
Wed Jul 2 02:46:57 CEST 2014


Hi Michael
Dates and times are always a problem as they are irregular not 1,2,3 ...,
100
If you want more fancy formatting of the x axis try this

First convert your time to a datetime class
# Use a dummy date for datetime as it is easier  
mmdat$time <- seq(strptime("20140702 14", "%Y%m%d %H"), by = "hours",
length= 24)
 # only gives numerical sequence on xlab
 plot(mmdat$wind_speed,type="b",xlab="Time")

However

 library(lattice)
 ?xyplot
# by starting at 15:00 hours get sequence and use formatting of dates 
xyplot(wind_speed ~time, data = mmdat,
        type = "b",
        xlab="Time",
        scales = list(x = list(at = seq(mmdat[2,1], by = "3 hours", length =
8),
                               labels = format(seq(mmdat[2,1], by = "3
hours", length = 8),"%H:%M")))
        )

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Michael Millar
Sent: Wednesday, 2 July 2014 03:42
To: r-help at R-project.org
Subject: [R] x axis labelling

Hi,

I am new to R and am trying to create a graph with Time(24hr) along the x
axis. Rather than start at 01.00, I wanted to start at 14.00.

I tried to use the axis(side=1, at=c(  )) function but it continues to put
then in numeric order. Is there another way I can add labels to the x axis?

Thank You.

Michael
 		 	   		  
	[[alternative HTML version deleted]]

______________________________________________
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.



More information about the R-help mailing list