[R-SIG-Mac]par(mfrow)

Andrew Beckerman a.p.beckerman@stir.ac.uk
Wed, 30 May 2001 10:12:44 +0100


Dear all -
Not sure if this is really a troublshooting list, but here goes.

Please reply to me, and to the list if folks think it is of general interest.

After running a simulation, I am trying to invoke a 2 row 1 column graph 
with par(mfrow=c(2,1))

This is followed by calling the two graphs where ngen is the number of reps 
the simulation has run and rt and at are vectors of length ngen

plot(c(1:ngen),at)
plot(c(1:ngen),rt)

I am getting a error message:

Error in plot.xy(xy,......: negative length vectors not allowed.

a check on the length of the vectors length() displays them as all 1000 
(ngen) and positive.

If i run the simulation without the par call, each plot prints separately.
If i run a different simulation, par works fine.

Any ideas?  (the code is below)

cheers,
andrew
--------------------------------------------------------------------------
#parameter values for the run
mu<-0.045; phi0<-0.0009; x<-1;

# set up parts of matrix that don't change over time
A<-matrix(0,11,11);
for (i in 1:9) {A[i+1,i]<-1};
A[11,11]<-1-mu;

#initial population
xt<-0*c(1:11); xt[11]<-10; xt[5:10]<-20;

ngen<-1000;
at<-matrix(0,ngen,1);
rt<-matrix(0,ngen,1);

for (j in 1:ngen){
         # recruitment
         xj<-x*(1+0.05*rnorm(1));
         phi<-xj/(sum(xt[5:10])+xt[11]);
         if(phi<phi0) r<-0 else r<-0.94*(phi-phi0)/(0.0044+(phi-phi0));
         A[11,10]<-r; A[10,10]<-(1-r)*(1-mu);
         rt[j]<-r;

         #fecundity
         f<-9.5*(phi^0.345); A[1,11]<-0.5*f;

# experimentally added adult mortality
#       drate<-0.2      *(1+0.05*rnorm(1));
    drate<-0;
         A[11,11]<-1-mu-drate;

         xt<-A%*%xt;
         at[j]<-xt[11];
}

par(mfrow=c(2,1));
plot(c(1:ngen),at,type="b",cex=1.5); title("Adults");
plot(c(1:ngen),rt,type="b",cex=1.5); title("Recruitment");




Dr. Andrew Beckerman
Institute of Biological Science
University of Stirling, Stirling FK9 4LA, Scotland, UK
phone:+44 (0)1786 467808 fax: +44 (0)1786 464994