AugustM
AugustM

Reputation: 87

Plot 4 confidence intervals with barplot2 (gplots)

I want to compare 4 confidence intervals. I have an example for doing it with 2 intervals, but cannot make it work with 4 side by side.

Here is the working script for 2 intervals. The VMP0$LOAD is my data.

CIA <- t.test(VMP0$NLoad)$conf.int
CIB <- t.test(VMP1$NLoad)$conf.int
#CIC <- t.test(VMP2$NLoad)$conf.int
#CID <- t.test(VMP3$NLoad)$conf.int

lower <- c(CIA[1], CIB[1])
upper <- c(CIA[2], CIB[2])
library(gplots)
barplot2(c(mean(VMP0$NLoad), mean(VMP1$NLoad)), 
         plot.ci = TRUE, ci.l = lower,    
         ci.u = upper,col = 2:3)

Upvotes: 0

Views: 647

Answers (1)

Mehdi Nellen
Mehdi Nellen

Reputation: 8964

How about this?

library(gplots)

# Just some example data
load1 <- 1:20
load2 <- 1:10
load3 <- 10:20
load4 <- 21:10

# uncomment this to make it work for your case
#load1 <- VMP0$NLoad
#load2 <- VMP1$NLoad
#load3 <- VMP2$NLoad
#load4 <- VMP3$NLoad

CIA <- t.test(load1)$conf.int   
CIB <- t.test(load2)$conf.int 
CIC <- t.test(load3)$conf.int 
CID <- t.test(load4)$conf.int 

lower <- c(CIA[1], CIB[1], CIC[1], CID[1])
upper <- c(CIA[2], CIB[2], CIC[2], CID[2])

barplot2(c(mean(load1), mean(load2), mean(load3), 
           mean(load4)), plot.ci = TRUE, 
         ci.l = lower, ci.u = upper,col = 2:3)

Next time add your data to your question so it can be reproduced.

Upvotes: 1

Related Questions