0

I would like to create a stacked barplot with unidirectional error bars (to avoid overlapping) in r. However, when I use the barplot2 function of gplots and omit besides=T, the automatic display of error bars is inhibited.

Here is a dummy dataset to represent my data:

BM=data.frame(Treatment=gl(3,4,24,labels=c("T1","T2","T3")),
Loc=gl(2,12,24,labels=letters[1:2]),Ind=gl(4,1,24,labels=c(1,2,3,4)),
Weight=runif(24))

I used the following codes:

mean.BM=tapply(Weight,list(Loc,Treatment),mean)
sd.BM=tapply(Weight,list(Loc,Treatment),sd)

bplot1=barplot2(mean.BM,panel.first=T,plot.ci=T,  
            ci.u=mean.BM+(0.5*sd.BM), col=c("grey30","grey80"))

Unfortunately I cannot post any images yet, I hope the question is clear anyway!

I am aware that there are probably more elegant ways to do this with ggplot2, but since I am not familiar with this package I would prefer a solution with gplots. If this is not possible, I am grateful for any other suggestion of course!

Jamie
  • 1
  • 1
  • 4
    You should post a subset of your dataset so that people can play around with it. – Dr. Mike Jul 18 '13 at 13:41
  • 3
    A stacked barplot with error bars? Makes me shudder at the very thought. – Roland Jul 18 '13 at 13:57
  • Agree w/ Roland. How could you display error ranges for the subsections of a stacked barplot? Further, stacked bars are one of the weakest ways of providing information to the reader. And what's "unidirectional" here? You seem to be calculating `mean /- sd`, after all. Let me point out one last thing: the error of a sum of RVs is not the sum of the errors, so you can't really plot a realistic error indicator in the first place. – Carl Witthoft Jul 18 '13 at 14:42
  • I updated my question and added a dummy dataset, I hope the question is clearer now. – Jamie Jul 19 '13 at 12:50
  • I'm a bit confused about the negative anwers concerning stacked barplots with error bars. I have seen this in publications before, and there are other posts dealing with this issue e.g. "Stacked barplot with errorbars using ggplot2". I am aware that barplots are not the best way to present data, but in this case it is not my choice to make so I would appreciate any constructive answer to this problem! – Jamie Jul 19 '13 at 12:56
  • @ Carl Witthoft:Thanks for your comment on `mean +/- sd`, that was a previous version of the code which I updated now. I would like to display only the upper part of the usual error bar to prevent overlapping between the subsections. – Jamie Jul 19 '13 at 13:14

0 Answers0