Re: [R] drawing segments through points with pch=1
David Epstein [EMAIL PROTECTED] 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. __ R-help@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.
Re: [R] drawing segments through points with pch=1
A. On Sun, 2008-07-20 at 15:40 +0100, David Epstein wrote: What I don't like about type=b, also suggested by Paul Smith, is that the segments do not go right up to the little circles---a gap is left, which I don't like. So far, Uwes' solution is what suits me best. However, I understand Brian's objection, though it doesn't apply in my case. The discussion makes me fear that it's a very long road ahead before I can get fine control of R graphics. Hi David, If you want to get transparency in the middle of the points and lines that connect them, try this: pointgap-strwidth(o)/2 segments(x[1:ll-1]+pointgap,ybar,x[2:ll]-pointgap,ybar) Jim __ R-help@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.
Re: [R] drawing segments through points with pch=1
DE == David Epstein [EMAIL PROTECTED] on Sun, 20 Jul 2008 15:40:34 +0100 writes: DE What I don't like about type=b, also suggested by Paul DE Smith, is that the segments do not go right up to the DE little circles---a gap is left, which I don't like. The gap is a feature; if you don't want it, use o ([o]verplotting lines and points)instead of b ([b]oth (lines and points) plot(x, ybarv, type=o, pch=21, bg=white) does in one line what Uwe's solution did in three. DE So far, Uwes' solution is what suits me best. However, I DE understand Brian's objection, though it doesn't apply in DE my case. The discussion makes me fear that it's a very DE long road ahead before I can get fine control of R DE graphics. I'd recommend you should really get and read Paul Murrell's book I just mentioned {in the other thread on R-help}, or read through the basic help pages points, lines, plot.default, ... quite carefully, and try and start to understand the many examples / demos etc. DE Thanks David DE On 20 Jul, 2008, at 14:54, Prof Brian Ripley wrote: On Sun, 20 Jul 2008, Uwe Ligges wrote: You probably want to make your code readable, read ?points and go ahead by making the plot without points (plot(., type=n)), drawing segments and at the end paint points with white background colour in order to overwrite the segments: Except that the background is not necessarily white (and you may want it to be transparent or translucent). It looks to me like lines(type=b) might be what was wanted. 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, type=n) segments(x[1], ybar, x[ll], ybar) points(x, ybarv, pch=21, bg=white) Uwe Ligges David Epstein 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. 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@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.
Re: [R] drawing segments through points with pch=1
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: [EMAIL PROTECTED] Alternative e-mail: [EMAIL PROTECTED] Message: 14 Date: Sun, 20 Jul 2008 13:44:27 +0100 From: David Epstein [EMAIL PROTECTED] Subject: [R] drawing segments through points with pch=1 To: r-help@r-project.org Message-ID: [EMAIL PROTECTED] 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@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.
[R] drawing segments through points with pch=1
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@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.
Re: [R] drawing segments through points with pch=1
On Sun, Jul 20, 2008 at 1:44 PM, David Epstein [EMAIL PROTECTED] 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. 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. What about replacing segments(x[1],ybar,x[ll],ybar) plot(x,ybarv,pch=1) with plot(x,ybarv,type=b) ? Paul __ R-help@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.
Re: [R] drawing segments through points with pch=1
On Sun, 20 Jul 2008, Uwe Ligges wrote: You probably want to make your code readable, read ?points and go ahead by making the plot without points (plot(., type=n)), drawing segments and at the end paint points with white background colour in order to overwrite the segments: Except that the background is not necessarily white (and you may want it to be transparent or translucent). It looks to me like lines(type=b) might be what was wanted. 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, type=n) segments(x[1], ybar, x[ll], ybar) points(x, ybarv, pch=21, bg=white) Uwe Ligges David Epstein 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. 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@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. __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.
Re: [R] drawing segments through points with pch=1
What I don't like about type=b, also suggested by Paul Smith, is that the segments do not go right up to the little circles---a gap is left, which I don't like. So far, Uwes' solution is what suits me best. However, I understand Brian's objection, though it doesn't apply in my case. The discussion makes me fear that it's a very long road ahead before I can get fine control of R graphics. Thanks David On 20 Jul, 2008, at 14:54, Prof Brian Ripley wrote: On Sun, 20 Jul 2008, Uwe Ligges wrote: You probably want to make your code readable, read ?points and go ahead by making the plot without points (plot(., type=n)), drawing segments and at the end paint points with white background colour in order to overwrite the segments: Except that the background is not necessarily white (and you may want it to be transparent or translucent). It looks to me like lines(type=b) might be what was wanted. 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, type=n) segments(x[1], ybar, x[ll], ybar) points(x, ybarv, pch=21, bg=white) Uwe Ligges David Epstein 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. 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@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. __ R-help@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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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.