Skip to content
Prev 199654 / 398502 Next

Automating Plot Commands using a Loop

I have three matrices with the same row and column names, but different data.

e.g.

Data
  Alpha Beta Gamma Delta
A  .1     .2       .3        .4  
B   .2    .3       .4        .5
C   .8   .9       .43       .13
D  .13   .34      .34      .3


For each column, I would like to create a separate plot on a single window.
I currently am using the cmd-line:

windows()
par(mfrow=c(2,2))
plot(Data$Alpha,type="o",axes=F,ann=F,ylim=c(0,1))
axis(1,at=1:4,lab=c("A","B","C","D")
axis(2,at=.25*0:1)
plot(Data$Beta,type="o",axes=F,ann=F,ylim=c(0,1))
axis(1,at=1:4,lab=c("A","B","C","D")
axis(2,at=.25*0:1)
etc.

I would like to automate this as much as possible. I tried to write a
function, but clearly it would involve some sort of loop... I don't know how
to do anything like that. 

Thanks,
koraelus