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

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Tue, 27 May 2008 17:38:12 +0200

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.



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. Received on Tue 27 May 2008 - 17:36:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 27 May 2008 - 18:30:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive