[R] several plots on several pages - bug in par(mfg())?
Francisco J. Zagmutt
gerifalte28 at hotmail.com
Sat Aug 18 06:59:42 CEST 2007
Hello Rainer,
You need to catch the cases where the call to plot generates an error.
Using your example:
## Set layout to three rows and only one column
par( mfcol=c(3,1), oma=c(0,0,0,0), mar=c(4, 4, 2, 2) )
## First row
par(mfg=c(1,1))
er<-try( plot(runif(ff)), silent=T ) ## plot fails due to something.
if (inherits(er, "try-error")) frame() else plot(runif(100))
## Second row
par(mfg=c(2,1))
try( plot(runif(100)) ) ##actually is plotted in first row
## Third row
par(mfg=c(3,1))
plot(runif(1000)) ## plotted in third row
See ?try ?inherits and ?frame
Notice that you will have to change plot(runif(ff)) to whatever plot you
are calling.
I hope this helps,
Francisco
Rainer M. Krug wrote:
> Greg Snow wrote:
>> Oops, I read further down in your original post and see that you already
>> knew about par(mfg=c(2,1)). To get it to advance to page 2 for the 4th
>> plot try calling plot.new() which should move you to the next page, then
>> doing par(mfg=c(1,1)) should cause the next graph to be at the top.
>>
>> Hope this helps,
>>
>
> Thanks - I found plot.new() and it is working.
>
> But: If the first plot command fails, par(mfg=c(2,1)) does NOT move to
> the second one - if you try the code below, you will see.
>
> Is this a bug or am I doing something wrong?
>
> ## Set layout to three rows and only oine column
> par( mfcol=c(3,1), oma=c(0,0,0,0), mar=c(4, 4, 2, 2) )
>
> ## First row
> par(mfg=c(1,1))
> try( plot(runif(ff)) ) ## plot fails due to something.
>
> ## Second row
> par(mfg=c(2,1))
> try( plot(runif(100)) ) ##actually is plotted in first row
>
> ## Third row
> par(mfg=c(3,1))
> plot(runif(1000)) ## plotted in third row
>
>
More information about the R-help
mailing list