using the arrows function to add confidence limits stored in a dataframe to a barplot

r

Solution

I suggest that instead of `barplot` and `arrows` functions, you use the much more flexible and powerful ggplot2 package. Here's how the `ggplot`, `geom_bar` and `geom_errorbar` functions can be used to create a barchart with confidence interval:

ggplot(data, aes(treatment, y, fill=1:6)) + geom_bar(position=position_dodge(), stat="identity") + geom_errorbar(aes(ymin=data$lower_limit_CI, ymax=data$upper_limit_CI), width=.2, position=position_dodge(.9))

The output looks like this:

Problem

I'm sure this is a simple problem for most of you :) I have looked around the R help pages and on here and I know what the function is that I need (arrows I think) but I just don't understand how to use it. So my question is: I have a dataframe (data) with the results of an experiment which I have simplified to this: ``` treatment y lower_limit_CI upper_limit_CI 1 0.13284413 0.1224 0.1438 2 0.263072558 0.2458 0.2809 3 0.234218546 0.217 0.2521 4 0.394980185 0.3702 0.4201 5 0.474533107 0.4457 0.5035 6 0.583333333 0.5526 0.6136 ``` I have drawn a barplot of the data like so: ``` plot <- barplot(data$y) ``` and I know that I now need the function arrows (yes?) to add the confidence limits also stored in my dataframe to the plot. Can someone please show me how to use arrows to get the correct info. from my dataframe? I have tried this on the advice of someone: ``` arrows(plot, data$y - data$lower_limit_CI, plot, data$y + data$upper_limit_CI, code=3, angle=90, length =0.1) ``` which gives giant bars which are obviously incorrect. Can anyone help? Thanks!

Original source