Skip to content
Prev 201866 / 398506 Next

Barplot with confidence intervals

On Nov 26, 2009, at 3:23 PM, Jonhnny Weslley wrote:

            
The data structures that you are passing to barplot2() are single  
column matrices. They need to be multicolumn matrices, where each  
column is a group and as per ?barplot2, the ci.l and ci.u arguments  
need to have the same structure as the height argument.

Thus:


 > DF
   Scenario1 Scenario1CIL Scenario1CIU Scenario2 Scenario2CIL
1        60           57           62        45           48
2       110          101          111        51           50
3       120          117          122        64           62
4       192          190          194        79           75
   Scenario2CIU
1           50
2           52
3           66
4           79


height <- as.matrix(DF[, c(1, 4)])
ci.l <- as.matrix(DF[, c(2, 5)])
ci.u <- as.matrix(DF[, c(3, 6)])

 > height
      Scenario1 Scenario2
[1,]        60        45
[2,]       110        51
[3,]       120        64
[4,]       192        79

 > ci.l
      Scenario1CIL Scenario2CIL
[1,]           57           48
[2,]          101           50
[3,]          117           62
[4,]          190           75

 > ci.u
      Scenario1CIU Scenario2CIU
[1,]           62           50
[2,]          111           52
[3,]          122           66
[4,]          194           79



library(gplots)

legend <- c("line1", "line2", "line3", "line4")

barplot2(height, plot.ci = TRUE, ci.l = ci.l, ci.u = ci.u,
          beside = TRUE, legend = legend, ylim = c(0, 200),
          main = "Experiment X", ylab = "Total size",
          font.main = 4, cex.axis = 1.2, cex.lab = 1.5,
          cex.names = 1.5, plot.grid = TRUE)


BTW, once you get the plot created, you may want to note some errors  
in your CI values.

HTH,

Marc Schwartz