2008/9/7 Anny Huang <[EMAIL PROTECTED]>: > 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 ______________________________________________ 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.