[R] axis command and excel time format

Carmen Meier carmei3 at web.de
Thu Nov 9 08:14:43 CET 2006


Gabor Grothendieck schrieb:
> Please provide a complete self contained example.  I can't follow the
> partial code below; however, its likely you are plotting one thing
> and creating axes using another so there is no reason it should
> come out right.
You are right  .. seems to be that it was too late at night ...

But I tried the right code and sent the wrong one ... the problem is 
still there


library(zoo)
library(chron)
time <- 
c("2:25:00","2:26:00","2:27:00","2:28:00","2:29:00","2:30:00","2:31:00",
        
"2:32:00","2:33:00","2:34:00","2:35:00","2:36:00","2:37:00","2:38:00",
         
"2:39:00","2:40:00","2:41:00","2:42:00","2:43:00","2:44:00","2:45:00",
        
"2:46:00","2:47:00","2:48:00","2:49:00","2:50:00","2:51:00","2:52:00",
          
"2:53:00","2:54:00","2:55:00","2:56:00","2:57:00","2:58:00","2:59:00",
          
"3:00:00","3:01:00","3:02:00","3:03:00","3:04:00","3:05:00","3:06:00",
          
"3:07:00","3:08:00","3:09:00","3:10:00","3:11:00","3:12:00","3:13:00",
          "3:14:00")
    min_time <- min(times(time))
    max_time <- max(times(time))

    duration <- max_time-min_time
      h <- hours(duration) # not nessesary here
    m <- minutes(duration)
    par(cex=1.2,lwd=1)
    range(x <- c(0,m)) #50 minutes
    range(y <- c(0,10))
    plot(x,y, type="n",adj=0, asp=0, xlab="", 
ylab="",axes=FALSE,font.axis=2)
#    axis(1, 0:m,font=2) # works fine but not with times

#---------- your suggestion --------
 mn <- times(min_time)
 mx <- times(max_time)
 n <- 12

 x <- times(seq(mn, mx, length = n))

 x <- times(unique(sub("..$", "00", x)))

 axis(1, x, sub(":00$", "", x)) # works only with plot data before
#----------------------
    axis(2, 0:10,font=2)
    box()


Best regards Carmen



More information about the R-help mailing list