[R] a little help needed plotting chron object

Randy Zelick zelickr at pdx.edu
Mon Nov 20 20:05:13 CET 2006


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



More information about the R-help mailing list