[R] Passing par()-parameters to many plot()s in a function

Duncan Murdoch murdoch.duncan at gmail.com
Fri Dec 3 22:09:50 CET 2010


On 03/12/2010 3:00 PM, Alexx Hardt wrote:
> Am 03.12.2010 20:31, schrieb Duncan Murdoch:
> >  On 03/12/2010 12:22 PM, Alexx Hardt wrote:
> >>  Hi,
> >>  I am implementing a function which generates about 10 .pdf plots in the
> >>  current directory.
> >>  I need the graphic to fit into a LaTeX-Presentation-slide, so the outer
> >>  margin should be removed (this is the way to do it, right?):
> >>
> >>  I am having trouble finding out where to put the par command(s). Is one
> >>  enough or should I put them before and after /every/ plot() command?
> >>  This is how I tried to do it (without success):
> >
> >  Generally speaking par() affects the current graphics device.  Your
> >  code below only opens one graphics device,
> >  so it should be fine to call par() once. (But you did forget to call
> >  dev.off(), so you will probably run into problems on the last plot.)
> >
> >  Another way to do this is to call pdf() and dev.off() 10 times.  The
> >  pdf.options() function sets defaults for a number of things related to
> >  a new pdf() device, but par() options are not included, so you'd need
> >  to call it before each plot.
> >
> >  There are surely some par() options that are cleared as you move to a
> >  new plot in your onefile=FALSE usage; I don't think the margin
> >  parameters are among them, but you might find it easiest just to set
> >  everything each time even if you are using only one pdf() device.
> >
>
> I did call dev.off(), I just forgot to copy it in the code snippet :)
> My problem was that I edited par()$oma and not par()$mar. oma defaults
> to c(0,0,0,0) so I couldn't shrink the margin with that command.
> Does it make a difference if I use the par() command before or after the
> pdf()-call to create the pdf device?

Yes, it will operate on the current device.  So if you call it before 
pdf(), it will give an error (if you have no device open) or will affect 
the current open device, not the new pdf() device.

Duncan Murdoch



More information about the R-help mailing list