Hello, I want to know how to draw a line connecting each point to the x-axis perpendicularly (i.e. a vertical line). abline(v=...) seems not to work for my purpose, because it runs over the data point. Can anyone help? Thanks. Anny [[alternative HTML version deleted]]
Anny Here's one way: plot(0:10, 0:10, pch=16) lines(rep(0:10, each=3), t(matrix(c(0:10, rep(c(0,NA), each=11)), ncol=3))) HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Anny Huang > Sent: Monday, 8 September 2008 8:49 a.m. > To: r-help at r-project.org > Subject: [R] how to draw a vertical line from points to x-axis > > Hello, > > I want to know how to draw a line connecting each point to > the x-axis perpendicularly (i.e. a vertical line). > abline(v=...) seems not to work for my purpose, because it > runs over the data point. Can anyone help? Thanks. > > Anny > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >The contents of this e-mail are privileged and/or confidential to the named recipient and are not to be used by any other person and/or organisation. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail.
Barry Rowlingson
2008-Sep-07 21:29 UTC
[R] how to draw a vertical line from points to x-axis
2008/9/7 Anny Huang <annylhuang at gmail.com>:> Hello, > > I want to know how to draw a line connecting each point to the x-axis > perpendicularly (i.e. a vertical line). > abline(v=...) seems not to work for my purpose, because it runs over the > data point. Can anyone help? Thanks. >If your x-axis is at y=zero then plot with type='h' will do this: plot(1:10,runif(10),type='h',ylim=c(0,1)) but it will draw lines *up* if the value is negative: plot(1:10,(1:10)-5,type='h') Or do you really want the lines to come right down to the axis line? In which case a modified version of Peter Alspach's solution which goes down to the limit of the plot instead of zero should work. See help(par) for what par()$usr is all about. y= 6+0:10 x=0:10 plot(x,y,pch=16,ylim=c(-2,17)) lines(rep(x,each=3),t(matrix(c(y,rep(c(par()$usr[3],NA),each=11)),ncol=3))) Barry
Adam D. I. Kramer
2008-Sep-08 22:27 UTC
[R] how to draw a vertical line from points to x-axis
I think you want the ?lines function. To connect a point (x,y) to the x-axis, lines(x=c(x,x),y=c(y,0)) ...draws a line from that point to the x-axis. You may also want to specify pch=c(?,""),type="b" where ? is the original point type (which you don't want to "run over") and "" is the pch for theline on the axis. --Adam On Sun, 7 Sep 2008, Anny Huang wrote:> Hello, > > I want to know how to draw a line connecting each point to the x-axis > perpendicularly (i.e. a vertical line). > abline(v=...) seems not to work for my purpose, because it runs over the > data point. Can anyone help? Thanks. > > Anny > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >