# R error bar question

 0 I have a local issue installing R packages for students, so I Googled a bit and found this nice code which plots error bars: my.values <- c(10, 5) err1 <- c(.5,.3) x <- barplot(my.values, ylim=c(0,12)) arrows(x,my.values-.5 ,x,my.values+.5, code=3, angle=90, length=.1) box() This works fine, but what I would like to do is adapt this to plot my own data, e.g. If I have two files of means and standard deviations: means <- c(34,47,58,46) stdevs <- c(19,29,20,19) how can I adapt the code so that I can plot this with the sd as the error bar on each mean value? asked 08 Mar '11, 14:13 AJCann 1●1●1●1 accept rate: 0%

One Answer:
 0 This example has some nice explanation that helped me to answer your question. ?barplot and ?arrows were also helpful for understanding all the options available ``````means <- c(34,47,58,46) stdevs <- c(19,29,20,19) barx <- barplot(means, ylim=c(0, max(means+stdevs))) # This assumes that the bars are all positive. If you expect negative data, you can do: # ylim=c(min(means-stdevs), max(means+stdevs)) arrows(barx, means+stdevs, barx, means-stdevs, angle=90, code=3, length=0.1) # barx stores the x positions for the arrows `````` If you actually have a comma-delimited file with the means in the first column and stdevs in the second column, you can modify the code as follows: ``````data <- read.csv("data.csv") means <- data[,1] stdevs <- data[,2] `````` answered 16 Mar '11, 15:49 BobC 1 accept rate: 0%
Your answer
 toggle preview community wiki

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• link:[text](http://url.com/ "title")
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

×2

Asked: 08 Mar '11, 14:13

Seen: 1,324 times

Last updated: 12 Jul, 08:06