Hi, I am trying to plot odds ratios and the corresponding confidence intervals in horizontal segments. It would be ideal if the confidence interval segment can be drawn with little vertical bars at both ends. I have tried very hard to change the type of ends by using 'lend' arguments, but cannot make it. I even tried 'arrows()', but still failed. Following is the code I use: ===================================================drug.or <- c(1.017,1.437,1.427,2.211) drug.orl <- c(0.715,1.075,1.103,1.696) drug.oru <- c(1.446,1.922,1.845,2.882) yaxis <- seq(1,4,by=1) plot(x=drug.or,y=yaxis,type='p',pch=17,xlim=c(0,3),axes=FALSE, xlab='Odds Ratio',ylab='',main='Reference Group: A only') axis(1,at=seq(0,3,by=0.5),labels=paste(seq(0,3,by=0.5))) axis(2,at=yaxis,las=2) segments(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,col=4,lend=2) # or try #arrows(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,length=0.1,angle=0,cod e=3,col=4,lend=2) box() ==================================================== Any comments or suggestions would be greatly appreciated. Jane University of Pittsburgh Pittsburgh, PA 15261
On Fri, 2006-07-07 at 11:47 -0400, Lu, Jiang Jane wrote:> Hi, > > I am trying to plot odds ratios and the corresponding confidence > intervals in horizontal segments. It would be ideal if the confidence > interval segment can be drawn with little vertical bars at both ends. I > have tried very hard to change the type of ends by using 'lend' > arguments, but cannot make it. I even tried 'arrows()', but still > failed. Following is the code I use: > ===================================================> drug.or <- c(1.017,1.437,1.427,2.211) > drug.orl <- c(0.715,1.075,1.103,1.696) > drug.oru <- c(1.446,1.922,1.845,2.882) > > yaxis <- seq(1,4,by=1) > > plot(x=drug.or,y=yaxis,type='p',pch=17,xlim=c(0,3),axes=FALSE, > xlab='Odds Ratio',ylab='',main='Reference Group: A only') > axis(1,at=seq(0,3,by=0.5),labels=paste(seq(0,3,by=0.5))) > axis(2,at=yaxis,las=2) > > > segments(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,col=4,lend=2) > > # or try > #arrows(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,length=0.1,angle=0,cod > e=3,col=4,lend=2) > > box() > ====================================================Try this using arrows(): drug.or <- c(1.017,1.437,1.427,2.211) drug.orl <- c(0.715,1.075,1.103,1.696) drug.oru <- c(1.446,1.922,1.845,2.882) yaxis <- seq(1, 4, by=1) plot(drug.or, yaxis ,type='p', pch=17, xlim=c(0,3), axes=FALSE, xlab='Odds Ratio', ylab='', main='Reference Group: A only') axis(1, at=seq(0,3,by=0.5), labels=paste(seq(0,3,by=0.5))) axis(2, at=yaxis, las=2) arrows(drug.orl, yaxis, drug.oru, yaxis, angle=90, length=0.1, code=3, col=4, lend=2) You need to specify an angle of 90 degrees to get the arrow heads to be perpendicular to the primary line segment. An angle of 0 superimposes the heads on the primary line segment, so they don't show. HTH, Marc Schwartz
You need angle=90. From the help page: angle: angle from the shaft of the arrow to the edge of the arrow head. On Fri, 7 Jul 2006, Lu, Jiang Jane wrote:> Hi, > > I am trying to plot odds ratios and the corresponding confidence > intervals in horizontal segments. It would be ideal if the confidence > interval segment can be drawn with little vertical bars at both ends. I > have tried very hard to change the type of ends by using 'lend' > arguments, but cannot make it. I even tried 'arrows()', but still > failed. Following is the code I use: > ===================================================> drug.or <- c(1.017,1.437,1.427,2.211) > drug.orl <- c(0.715,1.075,1.103,1.696) > drug.oru <- c(1.446,1.922,1.845,2.882) > > yaxis <- seq(1,4,by=1) > > plot(x=drug.or,y=yaxis,type='p',pch=17,xlim=c(0,3),axes=FALSE, > xlab='Odds Ratio',ylab='',main='Reference Group: A only') > axis(1,at=seq(0,3,by=0.5),labels=paste(seq(0,3,by=0.5))) > axis(2,at=yaxis,las=2) > > > segments(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,col=4,lend=2) > > # or try > #arrows(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,length=0.1,angle=0,cod > e=3,col=4,lend=2) > > box() > ====================================================> > > Any comments or suggestions would be greatly appreciated. > > > Jane > > University of Pittsburgh > Pittsburgh, PA 15261 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Brian D. Ripley, ripley at stats.ox.ac.uk 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, UK Fax: +44 1865 272595
Lu, Jiang Jane wrote:> Hi, > > I am trying to plot odds ratios and the corresponding confidence > intervals in horizontal segments. It would be ideal if the confidence > interval segment can be drawn with little vertical bars at both ends. I > have tried very hard to change the type of ends by using 'lend' > arguments, but cannot make it. I even tried 'arrows()', but still > failed. Following is the code I use: > ===================================================> drug.or <- c(1.017,1.437,1.427,2.211) > drug.orl <- c(0.715,1.075,1.103,1.696) > drug.oru <- c(1.446,1.922,1.845,2.882) > > yaxis <- seq(1,4,by=1) > > plot(x=drug.or,y=yaxis,type='p',pch=17,xlim=c(0,3),axes=FALSE, > xlab='Odds Ratio',ylab='',main='Reference Group: A only') > axis(1,at=seq(0,3,by=0.5),labels=paste(seq(0,3,by=0.5))) > axis(2,at=yaxis,las=2) > > > segments(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,col=4,lend=2) > > # or try > #arrows(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,length=0.1,angle=0,cod > e=3,col=4,lend=2)The call to arrows() seems to do what you want if angle=90. Also the lend argument seems unnecessary if you have angle=90.> box() > ====================================================> > > Any comments or suggestions would be greatly appreciated. > > > Jane > > University of Pittsburgh > Pittsburgh, PA 15261 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
On Fri, 2006-07-07 at 11:47 -0400, Lu, Jiang Jane wrote:> Hi, > > I am trying to plot odds ratios and the corresponding confidence > intervals in horizontal segments. It would be ideal if the confidence > interval segment can be drawn with little vertical bars at both ends. I > have tried very hard to change the type of ends by using 'lend' > arguments, but cannot make it. I even tried 'arrows()', but still > failed. Following is the code I use: > ===================================================> drug.or <- c(1.017,1.437,1.427,2.211) > drug.orl <- c(0.715,1.075,1.103,1.696) > drug.oru <- c(1.446,1.922,1.845,2.882) > > yaxis <- seq(1,4,by=1) > > plot(x=drug.or,y=yaxis,type='p',pch=17,xlim=c(0,3),axes=FALSE, > xlab='Odds Ratio',ylab='',main='Reference Group: A only') > axis(1,at=seq(0,3,by=0.5),labels=paste(seq(0,3,by=0.5))) > axis(2,at=yaxis,las=2) > > > segments(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,col=4,lend=2) > > # or try > #arrows(x0=drug.orl,x1=drug.oru,y0=yaxis,y1=yaxis,length=0.1,angle=0,cod > e=3,col=4,lend=2) > > box() > ====================================================> > > Any comments or suggestions would be greatly appreciated. > > > JaneHi Jane, Thanks for the reproducible example. Why do you think lend will do what you want? From ?par: 'lend' The line end style. This can be specified as an integer or string: '0' and '"round"' mean rounded line caps [_default_]; '1' and '"butt"' mean butt line caps; '2' and '"square"' mean square line caps. As from R 2.3.0 this can be specified inline. This is talking about line endings - do you want hard or soft line ends or type of joins in line segments? It does not mean the type of line endings you might get in Adobe Illustrator or Inkscape vector drawing packages. You were close with arrows: drug.or <- c(1.017,1.437,1.427,2.211) drug.orl <- c(0.715,1.075,1.103,1.696) drug.oru <- c(1.446,1.922,1.845,2.882) yaxis <- seq(1,4,by=1) plot(x = drug.or, y = yaxis, pch=17, xlim = c(0,3), axes=FALSE, xlab = 'Odds Ratio', ylab = '', main = 'Reference Group: A only') labs <- seq(0, 3, by = 0.5) axis(1, at = labs, labels = labs) axis(2, at = yaxis, las = 2) arrows(x0 = drug.orl, x1 = drug.oru, y0 = yaxis, y1 = yaxis, length=0.1, code = 3, col = 4, angle = 90) the angle argument is the key. See arrows? You don't need lend at all to do what you want. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC & ENSIS, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/cv/ London, UK. WC1E 6BT. [w] http://www.ucl.ac.uk/~ucfagls/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%