[R] Plotting only masked part of data

Joakim Hove hove at ift.uib.no
Tue Jan 25 14:57:18 CET 2005


Hello,

I have x and y data to plot (synthetic example):

  x <- seq(0,4*pi,by=0.1)
  y <- sin(x)

I then want to plot (x,y) in those points where abs(y) is smaller than
0.5. As a first approximation

  plot(x[abs(y) < 0.5],y[abs(y) < 0.5])

is quite close - however I want to plot with lines, i.e. type="l", and
then I get solid lines connecting the endpoint of one "active" region
to the start of the next active region, I would prefer to get rid of
those.

Lineart:
-------
 
   _____               ____
  / (1) \             / (3)\
 /       \           /      \
/         \         /        \
           \       /          \
            \_____/
              (2)


The problem is the horisontal lines shown as (1), (2) and (3) in the
schematic figure above, I would like to get rid of those,
i.e. retaining only four disconnected segments. I have started on a
programming based solution, plotting one piece at a time, but it is
*very* ugly!

Is there a simple general solution to my problem?



Regards

Joakim Hove

-- 
Joakim Hove
hove AT ift uib no
Tlf: +47 (55 5)8 27 90 
Fax: +47 (55 5)8 94 40
http://www.ift.uib.no/~hove/




More information about the R-help mailing list