[R] axis command and excel time format

Robert Baer rbaer at atsu.edu
Fri Nov 10 17:38:40 CET 2006


You should look at
?plot.default
?times
You need to supply an x vector (time) along with a y value vector of the 
same length. Your error message tells you that you vectors were not of equal 
length.  You are repeatedly supplying different length vectors.  times() 
takes a text vector and translates it into an object of class time. Try the 
following" to see if it unscrambles things for you.  You can go on to 
suppress axis labels, etc. by using other arguments as necessary .

xrange=times(c("2:25:00","3:14:00"))
yrange=c(0,10)
plot(xrange,yrange,type='n')


----- Original Message ----- 
From: "Carmen Meier" <carmei3 at web.de>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, November 10, 2006 5:13 AM
Subject: Re: [R] axis command and excel time format


> >
>>
>> Carmen,
>>
>> Gabor has already given you the detail you ask for, but might try the
>> following plot to see what is going wrong:
>>
>> plot(times(tt), x, type='l')
>>
>> This does not give you the EXACT control of the axis you asked for,
>> but this simple plot command gives you a fairly nice result. It
>> illustrates that your code is failing becasue you are plotting x
>> against the index of x rather than plotting x against time. At least
>> this is what I think the misunderstanding is.
>>
> Thank you Robert,
> this is nearly what I need,  but my problem is that I need an empty
> window with axes.
> I am able to build this with any data but not with the time axis.
> I need for a special issue only horizontal lines with different colors
> and arrows, which will be inserted from a function.
>
> Maybe you could explain me what's the difference between
> 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")
> y <- c(0,10)
> plot(times(time), y, type='n')
> -   error  in xy.coords(x, y, xlabel, ylabel, log) :    'x' and 'y'
> lengths differ
> -   the error is only with type='n' and not with type='l'
>
> and the example without errors
>
> 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")
> y <- c(0,10)
> plot(times(time), y, type='l')
>
>
> It is not the type='n' every other combination of data types which i
> tried  was working with the no plot option
> y <- c(0,10)
> z <- c(0,10)
> plot(z, y, type='n')
>
> Carmen
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list