[R] drawing segments through points with pch=1

Mike Prager mike.prager at noaa.gov
Tue Jul 22 19:16:00 CEST 2008


David Epstein <David.Epstein at warwick.ac.uk> wrote:

> Please excuse me for asking such basic questions:
> 
> Here is my code
> > y=c(1.21,0.51,0.14,1.62,-0.8,0.72,-1.71,0.84,0.02,-0.12)
> > ybar=mean(y)
> > ll=length(y);
> > ybarv=rep(ybar,ll)
> > x=1:ll
> > plot(x,ybarv,pch=1)
> > segments(x[1],ybar,x[ll],ybar)
> 
> What I get is a collection of small circles, with a segment "on top"  
> of the circles, which is almost what I want. But I don't want the  
> segment to be visible inside any small circle.
> 
> Is there an easy way to arrange for the segment to "lie behind" the  
> pch=1 markers, as in hidden line removal, so that the circles remain  
> with nothing inside them? I tried putting the segments command first,  
> but then no segment appeared at all.

Try using pch = 21 and the "bg" parameter to set the fill color.
That lets you set the background color of the circle so that it
will conceal the line segment.

In general in R graphics, objects are drawn in the order
specified. However, the default background of plotting symbols
is transparent, so in your case, the order doesn't matter.

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.



More information about the R-help mailing list