Skip to content
Prev 199691 / 398502 Next

Automating Plot Commands using a Loop

try this:

Data <- read.table(textConnection(" Alpha Beta Gamma Delta
A  .1     .2       .3        .4
B   .2    .3       .4        .5
C   .8   .9       .43       .13
D  .13   .34      .34      .3"), header=TRUE)
closeAllConnections()

par(mfrow=c(2,2))
for (i in colnames(Data)){
    plot(Data[[i]],type="o",axes=F,xlab='', ylab='', ylim=c(0,1), main=i)
    axis(1,at=1:4,lab=c("A","B","C","D"))
    axis(2,at=seq(0, 1, .25)) # changed your axis to work
}
On Mon, Nov 9, 2009 at 3:38 PM, Koraelus <koraelus at yahoo.com> wrote: