I'm trying to draw some error bars on a bar chart. I'm using code like this: thing <- c(3,3,3) se <- c(1,1,1) names(thing) <- c("A", "B", "C") barplot(thing, ylim=c(0,4)) arrows(c(1:3), thing-se, c(1:3), thing+se, code=3, angle=90,length=0.1) Using c(1:3) has 2 problems: 1. Obviously it is untidy, but using names(thing) doesn't work, and I can't find out what will work. 2. It draws the lines in the wrong place (i.e. not in the middle of the bars) I'm sure this problem has a well know and obvious solution, but it's not so well known or obvious to me. Thanks in advance. Bob -- Bob O'Hara Metapopulation Research Group Division of Population Biology Department of Ecology and Systematics PO Box 17 (Arkadiankatu 7) FIN-00014 University of Helsinki Finland NOTE: NEW TELEPHONE NUMBER tel: +358 9 191 28779 fax: +358 9 191 28701 email: bob.ohara at helsinki.fi To induce catatonia, visit: http://www.helsinki.fi/science/metapop/ It is being said of a certain poet, that though he tortures the English language, he has still never yet succeeded in forcing it to reveal his meaning - Beachcomber -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
there's a simple solution. barplot returns the locations of the horizontal centers of the bars, so replace your last two lines with something like: bloc <- barplot(thing, ylim=c(0,4)) arrows(bloc, thing-se, bloc, thing+se, code=3, angle=90,length=0.1) On Thu, 8 Nov 2001, Anon. wrote:> I'm trying to draw some error bars on a bar chart. I'm using code like > this: > > thing <- c(3,3,3) > se <- c(1,1,1) > names(thing) <- c("A", "B", "C") > barplot(thing, ylim=c(0,4)) > arrows(c(1:3), thing-se, c(1:3), thing+se, code=3, angle=90,length=0.1) > > Using c(1:3) has 2 problems: > 1. Obviously it is untidy, but using names(thing) doesn't work, and I > can't find out what will work. > 2. It draws the lines in the wrong place (i.e. not in the middle of the > bars) > > I'm sure this problem has a well know and obvious solution, but it's not > so well known or obvious to me. > > Thanks in advance. > > Bob > >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Anon." wrote:> > I'm trying to draw some error bars on a bar chart. I'm using code like > this: > > thing <- c(3,3,3) > se <- c(1,1,1) > names(thing) <- c("A", "B", "C") > barplot(thing, ylim=c(0,4)) > arrows(c(1:3), thing-se, c(1:3), thing+se, code=3, angle=90,length=0.1) > > Using c(1:3) has 2 problems: > 1. Obviously it is untidy, but using names(thing) doesn't work, and I > can't find out what will work. > 2. It draws the lines in the wrong place (i.e. not in the middle of the > bars) > > I'm sure this problem has a well know and obvious solution, but it's not > so well known or obvious to me.Barplot tells you where it has drawn the bars: temp <- barplot(thing, ylim=c(0,4)) arrows(temp, thing-se, temp, thing+se, code=3, angle=90,length=0.1) Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._