[R] error bars in matplot
Matthieu Dubois
matthdub at gmail.com
Thu Apr 16 20:35:09 CEST 2009
Hi Tim,
there are a couple of problems in your example.
(1) The most important is that your 'x' values for the matplot
are 1:5 (that is row numbers of your mat1 matrix)
and are seq(20,100,20) (that is, your vect vector) for your error bars.
Error bars are thus plotted outside the plotting area ...
(2) the ses2 variable is not defined in your example.
I thus modified your code accordingly :
library(plotrix)
mat1 <- matrix(sample(1:30,10),nrow=5,ncol=2)
ses <- sample(1:3,10,replace=T)
vect <- seq(20,100,20)
rownames(mat1) <- rownames(ses) <- vect
colnames(mat1) <- colnames(ses) <- letters[1:2]
# I added the vect vector as 'x' values.
# No more need to define the axes
# Just supressed the box around the plot with bty='n'
# to fit the look of your original plot
matplot(x=vect, y=mat1,
pch=c('x','o'), type = "b", lwd = 2, lty = c(1,2),
col = c("green","black"),
main = "Graph 1", xlab = "Numbers 1", ylab = "Numbers 2",
cex.main = 1.8, cex=2, cex.lab=1.5, cex.axis = 1.6, bty='n')
# I changed ses2 to ses and matrices to vectors
plotCI(x=rep(vect,2), y= as.vector(mat1),
uiw=as.vector(ses),
col=rep(c("green","black"),each=nrow(mat1)),
add=T)
HTH,
Matthieu
More information about the R-help
mailing list