I am surprised its not easier but this seems to give something
though the result is not beautiful:
plot(tv,yjunk,pch=yjl, xaxt = "n")
s <- seq(0, 1, .2)
axis(1, s, substr(chron(seq(0, 1, .2)), 11, 15))
On 11/20/06, Randy Zelick <zelickr at pdx.edu>
wrote:> Hello there,
>
> Using R 2.4.0 on Solaris (Unix):
>
> I am trying to control the X axis range on a simple time of day plot.
>
> I made a test program (below) that gets file time stamp information from
> the files in the directory where R starts. The goal of the test program is
> to plot the time of day of file creation on an x axis that spans a
> user-specified range (like 12:00:00 to 15:00:00).
>
> If I allow autoscaling I get nice time values on the plot. If I try to set
> an x range, instead I get numbers between 0 and 1 on the x axis.
>
> Test Program:
>
>
> library(chron)
>
> f=list.files() # GET THE LIST OF FILES IN THE CURRENT DIRECTORY
> f2=file.info(f) # FOR THE FILES, GET ALL THE INFO
> c5=f2[,5] # COLUMN 5 IS THE DATE & TIME STAMP
> print(c5) # LETS SEE IT
>
> of2=order(c5) # GENERATE ORDERING VECTOR
> c5o=c5[of2] # PUT FILE NAMES IN ORDER, IN A NEW VECTOR
> print(c5o) # LETS SEE IT
>
> dl=length(c5o) # HOW MANY FILES
> yjunk <- seq(from=1, to=dl, by=1) # MAKE A VECTOR OF Y VALUES
> yjl <- as.character(yjunk) # CONVERT Y'S TO CHARACTERS
>
> c5ot <- substr(c5o,11,20) # EXTRACT JUST THE TIME OF DAY INFO
>
> tv=chron(times=c5ot) # TURN TOD INTO CHRON OBJECT
>
> plot(tv,yjunk,pch=yjl) # PLOT DATA
>
> # ^^^(works with autoscaled x)
>
>
> tlow="00:00:00" # SET LOW TOD RANGE VARIABLE
> thigh="23:59:59" # SET HIGH TOD RANGE VARIABLE
> tl=chron(times=tlow) # TURN LOW TOD INTO CHRON OBJECT
> th=chron(times=thigh) # TURN HIGH TOD INTO CHRON OBJECT
>
> plot(tv,yjunk,pch=yjl,xlim=c(tl,th)) # PLOT DATA
>
> # ^^^(x labels converted to numbers between 0 and 1)
>
> =======================================================================>
> Thanks very much for your help.
>
> =Randy Zelick>
> R. Zelick email: zelickr at pdx.edu
> Department of Biology voice: 503-725-3086
> Portland State University fax: 503-725-3888
>
> mailing:
> P.O. Box 751
> Portland, OR 97207
>
> shipping:
> 1719 SW 10th Ave, Room 246
> Portland, OR 97201
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>