Skip to content
Prev 82498 / 398506 Next

plot

Rhett Eckstein wrote:
What do you want? Looking at your data makes me think you want two 
separate lines, in which case you probably want to do a plot() followed 
by a lines(), or better still with a slight rearrangement of your data 
you can use matplot() which is designed for doing several lines (or sets 
of points) in one plot.

Something like:

  matplot(C1$time[1:8], cbind(C1$X1[1:8], C1$X1[9:16]), type='l')

  but you may also want to rearrange your dataframe. Try:

  C2 = data.frame(time=C1$time[1:8], X1=C1$X1[1:8], X2=C1$X1[9:16])

  so it looks something like this (with random numbers):

  C2
   time          X1        X2
1  0.5 0.754514622 0.2571699
2  1.0 0.006056693 0.7252758
3  1.5 0.694433716 0.5532185
4  2.0 0.201020796 0.4590972
5  3.0 0.114225055 0.8226671
6  4.0 0.569609820 0.9712040
7  6.0 0.306018526 0.6795705
8  8.0 0.142492724 0.3452476

  then matplot becomes:

  matplot(C2$time, cbind(C2$X1,C2$X2),type='l')

  - sticking an NA in the middle (as suggested just now) seems a bit kludgy!

Baz