Re: [R] drawing segments through points with pch=1

From: Paulo Barata <pbarata_at_infolink.com.br>
Date: Mon, 21 Jul 2008 10:05:37 -0300

Dear Mr. Epstein,

This is another solution, two commands have been added to your own 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)
## cover the points with other points completely white: points(x,ybarv,pch=16,col='white')
## just write a black border over the white points (with pch=1) points(x,ybarv,pch=1,col='black')

The two new commands are layered on top of the previous ones. To write "on top" of a plot command, use the points command.

Regards,

Paulo Barata



Paulo Barata
Fundacao Oswaldo Cruz - Oswaldo Cruz Foundation Rua Leopoldo Bulhoes 1480 - 8A
21041-210 Rio de Janeiro - RJ
Brazil

E-mail: pbarata_at_infolink.com.br
Alternative e-mail: paulo.barata_at_ensp.fiocruz.br


>Message: 14
>Date: Sun, 20 Jul 2008 13:44:27 +0100
>From: David Epstein <David.Epstein_at_warwick.ac.uk>
>Subject: [R] drawing segments through points with pch=1
>To: r-help_at_r-project.org
>Message-ID: <B7CC24E1-9022-42F1-9BE2-914E73A22A60@warwick.ac.uk>
>Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
>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.

>
>In general, is there a method of laying a drawing "on top" of
>another. I tried inserting add="T" as an argument to plot, and R
>objected strongly.
>
>Thanks for any help
>
>David Epstein



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 21 Jul 2008 - 13:21:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 21 Jul 2008 - 14:32:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive