Skip to content

plot

5 messages · robin hankin, Barry Rowlingson, (Ted Harding) +1 more

#
Dear R users:
time        X1
1   0.5  6.296625
2   1.0 10.283977
3   1.5 12.718610
4   2.0 14.112740
5   3.0 15.053917
6   4.0 14.739725
7   6.0 12.912230
8   8.0 10.893264
9   0.5  6.289166
10  1.0 10.251247
11  1.5 12.651346
12  2.0 14.006958
13  3.0 14.870618
14  4.0 14.487026
15  6.0 12.555566
16  8.0 10.474695
In the plot, there is a straight line between time=0.5 and time=8,
If I do not want the straight line, what should I do?
Thanks for any help!!
#
Hi

insert a line of NAs into your data and the line won't
cross it:

 > a <- cbind(1:10,10:1)
 > aa <- a[append(1:10,NA,after=4),]
 > plot(aa,type="b")
 >


HTH

rksh
On 9 Dec 2005, at 11:48, Rhett Eckstein wrote:

            
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743
#
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
#
On 09-Dec-05 Rhett Eckstein wrote:
This happens because 'plot' is based on plotting the entire
series of points which you give it, whereas your data (on the
basis of the 'time' variable) consists of 2 series.

So the solution is to plit it:

  plot(C1[(1:8),],type="l",col="green")
  lines(C1[(9:16),],col="blue")

(where I've added the "col" option to illustrate how to identify
the two series by colour).

Best wishes,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 09-Dec-05                                       Time: 12:24:23
------------------------------ XFMail ------------------------------
#
Thank you first.
Now there is no straight line in the plot.
when i using:
 aa <- C1[append(1:16,NA,after=8),]
 plot(aa,type="l")

But if C1 is a more than 16 ( time v.s. X1 ) list.
for example: 64 (time v.s. X1)
 aa <- C1[append(1:64,NA,after=8),]
just let one line disappear, others still appear
what should I do ?
thank in advance!!


2005/12/9, Robin Hankin <r.hankin at noc.soton.ac.uk>: