[R] Odp: Help with lines when x-axis is a date

Petr PIKAL petr.pikal at precheza.cz
Tue May 27 17:38:12 CEST 2008


Hi

r-help-bounces at r-project.org napsal dne 27.05.2008 15:42:00:

> Hi...
> 
> I have a set of data, that looks like the following:
> 
> date mornenzyme niteenzyme pdate
> 
> where date is the original data char string and pdate is the POSIX 
> representation.
> mornenzyme and niteenzyme are both float values.
> 
> What I want to do is plot pdate against both enzymes, by having a 
> small blue circle
> where the nite enzyme reading is and a red in the morning and for 
> each date, have
> them connected by a line.
> 
> I can easily do the points with a plot followed by a points command, 
> but the line
> has me stumped. I tried:
> 
> for(i in length(enz[,1]) {
> lines(c(pdate[i],mornenzyme[i]),c(pdate[i],niteenzyme[i]))
> }
> 
> ...but nothing plots. No line, no nothing and no error. Seems to be 
> an issue when a date is
> used as the x-axis. Not sure what the solution to this is. Any help 
> appreciated.

Well it is rather difficult but:

with c(pdate[i],mornenzyme[i]) you change your mornenzyme data to date 
format and then you plot date on x axis and date on y axis which is 
probably not what you want.

I would change your data to

pdata enzyme daytime
....  ....   morning
....  ....   ....
....  ....   night

then I would plot
plot(pdata, enzyme, type=n)

and after that I would use
for (i in unique(daytime)) lines(pdata[daytime==i], enzyme[daytime==i], 
col=i, ...)
Do not forget to attach your data frame or to use full path or with 
function.

However there are probably other options too, as usual with R.

Regards
Petr









> 
> PS: No...this is not time-series data, hence, cannot use ts.plot.
> 
> TIA
> Joe
> 
> ______________________________________________
> 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