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. PS: No...this is not time-series data, hence, cannot use ts.plot. TIA Joe
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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Joe Trubisz wrote:> 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. > > PS: No...this is not time-series data, hence, cannot use ts.plot.Hi Joe, When I look at your for loop, you are only going through it once. Say you try this and use segments: for(i in 1:length(enz[,1]) { segments(pdate[i],mornenzyme[i],pdate[i],niteenzyme[i]) } Now this should give you a bunch of vertical lines, as the x component is the same for the start and end of each line. However, I think you can probably work out how to get around that. Jim