Is there an easy way to make the error bars the same color as the points and lines they are plotted with. My example # fake data x=sample(1:10, 100, replace =T) y = rnorm(100) + runif(100) df=data.frame(x,y) # summarize data m = aggregate(df,list(x),mean) se = aggregate(df,list(x),sd)/sqrt(10) library(Hmisc) plot(x,y) errbar(m$x, m$y, m$y+1.96*se$y, m$y-1.96*se$y,col='red',cex=2,type='b',add=TRUE) Thanks, Rob ------------------------------------------ Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A. T. Still University of Health Sciences Kirksville, MO 63501 660-626-232 FAX 660-626-2965 [[alternative HTML version deleted]]
On 2011-02-09 17:27, Robert Baer wrote:> Is there an easy way to make the error bars the same color as the points and lines they are plotted with. > > My example > # fake data > x=sample(1:10, 100, replace =T) > y = rnorm(100) + runif(100) > df=data.frame(x,y) > # summarize data > m = aggregate(df,list(x),mean) > se = aggregate(df,list(x),sd)/sqrt(10) > library(Hmisc) > plot(x,y) > errbar(m$x, m$y, m$y+1.96*se$y, m$y-1.96*se$y,col='red',cex=2,type='b',add=TRUE)Try inserting par(fg = "red") between your plot() and errbar() statements. Peter Ehlers> > Thanks, > Rob > > > ------------------------------------------ > Robert W. Baer, Ph.D. > Professor of Physiology > Kirksville College of Osteopathic Medicine > A. T. Still University of Health Sciences > Kirksville, MO 63501 > 660-626-232 > FAX 660-626-2965 > > [[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.
On Feb 9, 2011, at 8:27 PM, Robert Baer wrote:> Is there an easy way to make the error bars the same color as the > points and lines they are plotted with. > > My example > # fake data > x=sample(1:10, 100, replace =T) > y = rnorm(100) + runif(100) > df=data.frame(x,y) > # summarize data > m = aggregate(df,list(x),mean) > se = aggregate(df,list(x),sd)/sqrt(10) > library(Hmisc) > plot(x,y) > errbar(m$x, m$y, m$y+1.96*se$y, m$y-1.96*se > $y,col='red',cex=2,type='b',add=TRUE)If you look at the errbar code you see that it is not lattice (yet?) but rather base graphics based. The bars appear to be drawn with segments() and the arguments to segments (from its help page: segments(x0, y0, x1 = x0, y1 = y0, col = par("fg"), lty = par("lty"), lwd = par("lwd"), ...) So I would think you should be trying to use par(fg="red"). (I know you didn't ask but the large solid red points at the means strike me as ugly. My suggestion would be open diamonds achieved with pch=23) par(fg="red") errbar(m$x, m$y, m$y+1.96*se$y, m$y-1.96*se $y,col='red',cex=2,type='b',add=TRUE, pch=23) par(fg="black") -- David Winsemius, MD West Hartford, CT