several plots on several pages

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

several plots on several pages

Rainer M Krug-3
Hi

 > version
                _
platform       i686-pc-linux-gnu
arch           i686
os             linux-gnu
system         i686, linux-gnu
status
major          2
minor          5.1
year           2007
month          06
day            27
svn rev        42083
language       R
version.string R version 2.5.1 (2007-06-27)



I want to create a pdf withe three graphs on a page and with two pages:

-------------
|     1     |
-------------
|     2     |
-------------
|     3     |
-------------

NEW PAGE

-------------
|     4     |
-------------
|     5     |
-------------
|     6     |
-------------

Graph 1 should ALWAYS be at that spot, graph two also, even if graph one
produces an error when plotting (the area can be empty, but doesn't have
to.)

I produced the foolowing code below, but I have a few problems:

1) how can I create a new page in the pdf?

2) how can I make sure that the second graph is in position 2 when graph
one produces an error when plotting I(as in the example)? Everything
works OK (for the firsat page) when graph one is plotted.

I have the feeling, that I am thinking to complicated.

Any help welcome,

Rainer


pdf("test.pdf")
try(
     {
     ## 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)) )

     ## Second row
     par(mfg=c(2,1))
     try( plot(runif(100)) )

     ## Third row
     par(mfg=c(3,1))
     plot(runif(1000))


     ## THE NEXT THREE SHOULD BE ON A NEW PAGE IN THE PDF

     ## 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)) )

     ## Second row
     par(mfg=c(2,1))
     try( plot(runif(100)) )

     ## Third row
     par(mfg=c(3,1))
     plot(runif(1000))

     }
     )
dev.off()


--
NEW EMAIL ADDRESS AND ADDRESS:

[hidden email]

[hidden email] WILL BE DISCONTINUED END OF MARCH

Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Plant Conservation Unit
Department of Botany
University of Cape Town
Rondebosch 7701
South Africa

Tel: +27 - (0)21 650 5776 (w)
Fax: +27 - (0)86 516 2782
Fax: +27 - (0)21 650 2440 (w)
Cell: +27 - (0)83 9479 042

Skype: RMkrug

email: [hidden email]
        [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages

Thierry Onkelinx
Dear Rainer,

Have you considered using Sweave?

HTH,

Thierry

------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[hidden email]
www.inbo.be

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

 

> -----Oorspronkelijk bericht-----
> Van: [hidden email]
> [mailto:[hidden email]] Namens Rainer M. Krug
> Verzonden: donderdag 16 augustus 2007 14:58
> Aan: r-help
> Onderwerp: [R] several plots on several pages
>
> Hi
>
>  > version
>                 _
> platform       i686-pc-linux-gnu
> arch           i686
> os             linux-gnu
> system         i686, linux-gnu
> status
> major          2
> minor          5.1
> year           2007
> month          06
> day            27
> svn rev        42083
> language       R
> version.string R version 2.5.1 (2007-06-27)
>
>
>
> I want to create a pdf withe three graphs on a page and with
> two pages:
>
> -------------
> |     1     |
> -------------
> |     2     |
> -------------
> |     3     |
> -------------
>
> NEW PAGE
>
> -------------
> |     4     |
> -------------
> |     5     |
> -------------
> |     6     |
> -------------
>
> Graph 1 should ALWAYS be at that spot, graph two also, even
> if graph one produces an error when plotting (the area can be
> empty, but doesn't have
> to.)
>
> I produced the foolowing code below, but I have a few problems:
>
> 1) how can I create a new page in the pdf?
>
> 2) how can I make sure that the second graph is in position 2
> when graph one produces an error when plotting I(as in the
> example)? Everything works OK (for the firsat page) when
> graph one is plotted.
>
> I have the feeling, that I am thinking to complicated.
>
> Any help welcome,
>
> Rainer
>
>
> pdf("test.pdf")
> try(
>      {
>      ## 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)) )
>
>      ## Second row
>      par(mfg=c(2,1))
>      try( plot(runif(100)) )
>
>      ## Third row
>      par(mfg=c(3,1))
>      plot(runif(1000))
>
>
>      ## THE NEXT THREE SHOULD BE ON A NEW PAGE IN THE PDF
>
>      ## 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)) )
>
>      ## Second row
>      par(mfg=c(2,1))
>      try( plot(runif(100)) )
>
>      ## Third row
>      par(mfg=c(3,1))
>      plot(runif(1000))
>
>      }
>      )
> dev.off()
>
>
> --
> NEW EMAIL ADDRESS AND ADDRESS:
>
> [hidden email]
>
> [hidden email] WILL BE DISCONTINUED END OF MARCH
>
> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>
> Plant Conservation Unit
> Department of Botany
> University of Cape Town
> Rondebosch 7701
> South Africa
>
> Tel: +27 - (0)21 650 5776 (w)
> Fax: +27 - (0)86 516 2782
> Fax: +27 - (0)21 650 2440 (w)
> Cell: +27 - (0)83 9479 042
>
> Skype: RMkrug
>
> email: [hidden email]
>         [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages

Rainer M Krug-3
Hi Thierry

ONKELINX, Thierry wrote:
> Dear Rainer,
>
> Have you considered using Sweave?

No - and I am sure it will do what I want, but I guess it might be an
overkill. These arew just draft outputs for myself for different
datasets which should be easy to compare. SO I guess that Sweave might
be an overkill (especially as I found plot.new() which jumpd to a new page).

Thanks and I will keep it in mind for the future,

Rainer


>
> HTH,
>
> Thierry
>
> ------------------------------------------------------------------------
> ----
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
> and Forest
> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
> methodology and quality assurance
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium
> tel. + 32 54/436 185
> [hidden email]
> www.inbo.be
>
> Do not put your faith in what statistics say until you have carefully
> considered what they do not say.  ~William W. Watt
> A statistical analysis, properly conducted, is a delicate dissection of
> uncertainties, a surgery of suppositions. ~M.J.Moroney
>
>  
>
>> -----Oorspronkelijk bericht-----
>> Van: [hidden email]
>> [mailto:[hidden email]] Namens Rainer M. Krug
>> Verzonden: donderdag 16 augustus 2007 14:58
>> Aan: r-help
>> Onderwerp: [R] several plots on several pages
>>
>> Hi
>>
>>  > version
>>                 _
>> platform       i686-pc-linux-gnu
>> arch           i686
>> os             linux-gnu
>> system         i686, linux-gnu
>> status
>> major          2
>> minor          5.1
>> year           2007
>> month          06
>> day            27
>> svn rev        42083
>> language       R
>> version.string R version 2.5.1 (2007-06-27)
>>
>>
>>
>> I want to create a pdf withe three graphs on a page and with
>> two pages:
>>
>> -------------
>> |     1     |
>> -------------
>> |     2     |
>> -------------
>> |     3     |
>> -------------
>>
>> NEW PAGE
>>
>> -------------
>> |     4     |
>> -------------
>> |     5     |
>> -------------
>> |     6     |
>> -------------
>>
>> Graph 1 should ALWAYS be at that spot, graph two also, even
>> if graph one produces an error when plotting (the area can be
>> empty, but doesn't have
>> to.)
>>
>> I produced the foolowing code below, but I have a few problems:
>>
>> 1) how can I create a new page in the pdf?
>>
>> 2) how can I make sure that the second graph is in position 2
>> when graph one produces an error when plotting I(as in the
>> example)? Everything works OK (for the firsat page) when
>> graph one is plotted.
>>
>> I have the feeling, that I am thinking to complicated.
>>
>> Any help welcome,
>>
>> Rainer
>>
>>
>> pdf("test.pdf")
>> try(
>>      {
>>      ## 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)) )
>>
>>      ## Second row
>>      par(mfg=c(2,1))
>>      try( plot(runif(100)) )
>>
>>      ## Third row
>>      par(mfg=c(3,1))
>>      plot(runif(1000))
>>
>>
>>      ## THE NEXT THREE SHOULD BE ON A NEW PAGE IN THE PDF
>>
>>      ## 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)) )
>>
>>      ## Second row
>>      par(mfg=c(2,1))
>>      try( plot(runif(100)) )
>>
>>      ## Third row
>>      par(mfg=c(3,1))
>>      plot(runif(1000))
>>
>>      }
>>      )
>> dev.off()
>>
>>
>> --
>> NEW EMAIL ADDRESS AND ADDRESS:
>>
>> [hidden email]
>>
>> [hidden email] WILL BE DISCONTINUED END OF MARCH
>>
>> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>>
>> Plant Conservation Unit
>> Department of Botany
>> University of Cape Town
>> Rondebosch 7701
>> South Africa
>>
>> Tel: +27 - (0)21 650 5776 (w)
>> Fax: +27 - (0)86 516 2782
>> Fax: +27 - (0)21 650 2440 (w)
>> Cell: +27 - (0)83 9479 042
>>
>> Skype: RMkrug
>>
>> email: [hidden email]
>>         [hidden email]
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>


--
NEW EMAIL ADDRESS AND ADDRESS:

[hidden email]

[hidden email] WILL BE DISCONTINUED END OF MARCH

Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Plant Conservation Unit
Department of Botany
University of Cape Town
Rondebosch 7701
South Africa

Tel: +27 - (0)21 650 5776 (w)
Fax: +27 - (0)86 516 2782
Fax: +27 - (0)21 650 2440 (w)
Cell: +27 - (0)83 9479 042

Skype: RMkrug

email: [hidden email]
        [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages

Gregory Snow
In reply to this post by Rainer M Krug-3
You can set up the 3 plots per page by using:

> par(mfrow=c(3,1))

Then there are a couple of options for skipping the top graphics
position if the graph fails.  If you know that the graph failed then you
can just use plot.new() (or frame()) to skip the top plot and plot the
next one in the 2nd position.

Another option is you can call par(mfg=c(2,1)) explicitly before
plotting the 2nd plot to force it to plot in the 2,1 position.

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Rainer M. Krug
> Sent: Thursday, August 16, 2007 6:58 AM
> To: r-help
> Subject: [R] several plots on several pages
>
> Hi
>
>  > version
>                 _
> platform       i686-pc-linux-gnu
> arch           i686
> os             linux-gnu
> system         i686, linux-gnu
> status
> major          2
> minor          5.1
> year           2007
> month          06
> day            27
> svn rev        42083
> language       R
> version.string R version 2.5.1 (2007-06-27)
>
>
>
> I want to create a pdf withe three graphs on a page and with
> two pages:
>
> -------------
> |     1     |
> -------------
> |     2     |
> -------------
> |     3     |
> -------------
>
> NEW PAGE
>
> -------------
> |     4     |
> -------------
> |     5     |
> -------------
> |     6     |
> -------------
>
> Graph 1 should ALWAYS be at that spot, graph two also, even
> if graph one produces an error when plotting (the area can be
> empty, but doesn't have
> to.)
>
> I produced the foolowing code below, but I have a few problems:
>
> 1) how can I create a new page in the pdf?
>
> 2) how can I make sure that the second graph is in position 2
> when graph one produces an error when plotting I(as in the
> example)? Everything works OK (for the firsat page) when
> graph one is plotted.
>
> I have the feeling, that I am thinking to complicated.
>
> Any help welcome,
>
> Rainer
>
>
> pdf("test.pdf")
> try(
>      {
>      ## 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)) )
>
>      ## Second row
>      par(mfg=c(2,1))
>      try( plot(runif(100)) )
>
>      ## Third row
>      par(mfg=c(3,1))
>      plot(runif(1000))
>
>
>      ## THE NEXT THREE SHOULD BE ON A NEW PAGE IN THE PDF
>
>      ## 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)) )
>
>      ## Second row
>      par(mfg=c(2,1))
>      try( plot(runif(100)) )
>
>      ## Third row
>      par(mfg=c(3,1))
>      plot(runif(1000))
>
>      }
>      )
> dev.off()
>
>
> --
> NEW EMAIL ADDRESS AND ADDRESS:
>
> [hidden email]
>
> [hidden email] WILL BE DISCONTINUED END OF MARCH
>
> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>
> Plant Conservation Unit
> Department of Botany
> University of Cape Town
> Rondebosch 7701
> South Africa
>
> Tel: +27 - (0)21 650 5776 (w)
> Fax: +27 - (0)86 516 2782
> Fax: +27 - (0)21 650 2440 (w)
> Cell: +27 - (0)83 9479 042
>
> Skype: RMkrug
>
> email: [hidden email]
>         [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages

Gregory Snow
In reply to this post by Rainer M Krug-3
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,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
(801) 408-8111
 
 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Rainer M. Krug
> Sent: Thursday, August 16, 2007 6:58 AM
> To: r-help
> Subject: [R] several plots on several pages
>
> Hi
>
>  > version
>                 _
> platform       i686-pc-linux-gnu
> arch           i686
> os             linux-gnu
> system         i686, linux-gnu
> status
> major          2
> minor          5.1
> year           2007
> month          06
> day            27
> svn rev        42083
> language       R
> version.string R version 2.5.1 (2007-06-27)
>
>
>
> I want to create a pdf withe three graphs on a page and with
> two pages:
>
> -------------
> |     1     |
> -------------
> |     2     |
> -------------
> |     3     |
> -------------
>
> NEW PAGE
>
> -------------
> |     4     |
> -------------
> |     5     |
> -------------
> |     6     |
> -------------
>
> Graph 1 should ALWAYS be at that spot, graph two also, even
> if graph one produces an error when plotting (the area can be
> empty, but doesn't have
> to.)
>
> I produced the foolowing code below, but I have a few problems:
>
> 1) how can I create a new page in the pdf?
>
> 2) how can I make sure that the second graph is in position 2
> when graph one produces an error when plotting I(as in the
> example)? Everything works OK (for the firsat page) when
> graph one is plotted.
>
> I have the feeling, that I am thinking to complicated.
>
> Any help welcome,
>
> Rainer
>
>
> pdf("test.pdf")
> try(
>      {
>      ## 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)) )
>
>      ## Second row
>      par(mfg=c(2,1))
>      try( plot(runif(100)) )
>
>      ## Third row
>      par(mfg=c(3,1))
>      plot(runif(1000))
>
>
>      ## THE NEXT THREE SHOULD BE ON A NEW PAGE IN THE PDF
>
>      ## 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)) )
>
>      ## Second row
>      par(mfg=c(2,1))
>      try( plot(runif(100)) )
>
>      ## Third row
>      par(mfg=c(3,1))
>      plot(runif(1000))
>
>      }
>      )
> dev.off()
>
>
> --
> NEW EMAIL ADDRESS AND ADDRESS:
>
> [hidden email]
>
> [hidden email] WILL BE DISCONTINUED END OF MARCH
>
> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>
> Plant Conservation Unit
> Department of Botany
> University of Cape Town
> Rondebosch 7701
> South Africa
>
> Tel: +27 - (0)21 650 5776 (w)
> Fax: +27 - (0)86 516 2782
> Fax: +27 - (0)21 650 2440 (w)
> Cell: +27 - (0)83 9479 042
>
> Skype: RMkrug
>
> email: [hidden email]
>         [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages - bug in par(mfg())?

Rainer M Krug-3
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


--
NEW EMAIL ADDRESS AND ADDRESS:

[hidden email]

[hidden email] WILL BE DISCONTINUED END OF MARCH

Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Plant Conservation Unit
Department of Botany
University of Cape Town
Rondebosch 7701
South Africa

Tel: +27 - (0)21 650 5776 (w)
Fax: +27 - (0)86 516 2782
Fax: +27 - (0)21 650 2440 (w)
Cell: +27 - (0)83 9479 042

Skype: RMkrug

email: [hidden email]
        [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages - bug in par(mfg())?

Thierry Onkelinx
Dear Rainer,

Your could try something like this.

test <- try( plot(runif(ff)) )
if(class(test) == "try-error"){
        #put here code for an empty plot
}

Cheers,

Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
[hidden email]
www.inbo.be

Do not put your faith in what statistics say until you have carefully
considered what they do not say.  ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney

 

> -----Oorspronkelijk bericht-----
> Van: [hidden email]
> [mailto:[hidden email]] Namens Rainer M. Krug
> Verzonden: vrijdag 17 augustus 2007 9:49
> Aan: Greg Snow
> CC: r-help; [hidden email]
> Onderwerp: Re: [R] several plots on several pages - bug in par(mfg())?
>
> 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
>
>
> --
> NEW EMAIL ADDRESS AND ADDRESS:
>
> [hidden email]
>
> [hidden email] WILL BE DISCONTINUED END OF MARCH
>
> Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT)
>
> Plant Conservation Unit
> Department of Botany
> University of Cape Town
> Rondebosch 7701
> South Africa
>
> Tel: +27 - (0)21 650 5776 (w)
> Fax: +27 - (0)86 516 2782
> Fax: +27 - (0)21 650 2440 (w)
> Cell: +27 - (0)83 9479 042
>
> Skype: RMkrug
>
> email: [hidden email]
>         [hidden email]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: several plots on several pages - bug in par(mfg())?

Francisco J. Zagmutt
In reply to this post by Rainer M Krug-3
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
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.