[R] error bars in matplot

Jim Lemon jim at bitwrit.com.au
Fri Apr 17 13:45:39 CEST 2009


Tim Smith wrote:
> Hi,
>
> I was trying to get error bars in my matplot. I looked at an earlier thread, and the sample code that I made is:
>
> #------------------
> library(plotrix)
>
> mat1 <- matrix(sample(1:30,10),nrow=5,ncol=2)
> ses <- matrix(sample(1:3,10,replace=T),nrow=5,ncol=2)
> vect <- seq(20,100,20)
> rownames(mat1) <- rownames(ses) <- vect
> colnames(mat1) <- colnames(ses) <- letters[1:2]
>
> matplot(mat1,pch=c('x','o'),type = "b",lwd = 2,lty = c(1,2),
>     col = c("green","black"),cex.main = 1.8,cex=2,cex.lab=1.5,
>     main = "Graph 1",xlab = "Numbers 1",ylab = "Numbers 2",cex.axis = 1.6,axes=F)
> plotCI(rep(vect,2),mat1,ses2,pch=NA,add=T,
>         col=rep(c("green","black"),each=nrow(mat1)))
> axis(1,1:5,labels = vect,cex.axis=1.5)
> axis(2,cex.axis=1.5)
>   
> #------------------
>
> I don't get the error bars though. If I set 'add = F' in plotCI function, then I can see the error bars, but they just can't be added to the matplot. What am I doing wrong? Is there any other way to get the error bars?
>
>   
Hi Tim,
Try the dispersion function in plotrix to add error bars. You will 
probably have to add ylim=c(0,29) to your matplot command.

dispersion(rep(1:5,2),mat1,ses)

Jim




More information about the R-help mailing list