-1

I would like to produce a similar graph to this link. However, I would like to show error bars for each mean and I'm not sure how to do this in R. I want to plot MeansG1 and MeansG2 as separate plots. My data:

data<-structure(list(MeansG1=c(10.780877,8.675726,10.398065,11.617315,12.231693,8.292337,8.093416,10.744478,10.531539,11.459219,12.316292,11.272801),
                 STEG1=c(0.2578710,0.2569172,0.2502743,0.2558724,0.2523819,0.2427068,0.2507437,0.2475850,0.2421691,0.2365641,0.2350861,0.2312222),
                 MeansG2=c(11.780877,9.675726,11.398065,12.617315,13.231693,12.292337,12.093416,12.744478,12.531539,11.459219,12.316292,12.272801),
                 STEG2=c(0.2578710,0.2569172,0.2502743,0.2558724,0.2523819,0.2427068,0.2507437,0.2475850,0.2421691,0.2365641,0.2350861,0.2312222)),
            .Names = c("MeansG1", "STEG1", "MeansG2", "STEG2"), row.names=1:12,class = "data.frame")    

Thanks.

Community
  • 1
  • 1
user27241
  • 201
  • 3
  • 10

1 Answers1

0

i prefer polygon() for this kind of task. below is an example using your data. i hope it helps and let me know if anything needs explaining.

# get the data ready
g1 <- data.frame(mean = data$MeansG1,
                 up = data$MeansG1 + data$STEG1,
                 down = data$MeansG1 - data$STEG1)
g2 <- data.frame(mean = data$MeansG2,
                 up = data$MeansG2 + data$STEG2,
                 down = data$MeansG2 - data$STEG2)
plotData <- list(g1, g2)

# setup the plotting region
par(mfcol = c(2, 1))

### make the plots
for(i in plotData){
    dd <- i
    plot(dd$mean, type = "n", ylim = range(dd))
    xvals <- 1:dim(dd)[1]
    polygon(c(xvals, rev(xvals)), c(dd$up, rev(dd$down)), col = "#ff000050", border = NA)
    lines(dd$mean, col = "red")
}
roman
  • 1,340
  • 9
  • 33