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

Jim Lemon jim at bitwrit.com.au
Wed May 28 10:46:53 CEST 2008


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



More information about the R-help mailing list