[R] best way to globally set parameters for base graphics

Duncan Murdoch murdoch.duncan at gmail.com
Mon Jul 20 17:48:27 CEST 2015


On 20/07/2015 11:27 AM, Martin Batholdy via R-help wrote:
> Hi,
> 
> I am looking for a way to modify the basic setup for any kind of plot.
> (everything that is set with the par function – like margins, cex, las etc.)
> 
> I want to do this once – preferably across R sessions and not individually before every plot.
> 
> 
> My first attempt was to add a par() with all my own defaults to the .Rprofile file.
> This obviously does not work because par opens a new drawing device, applying its effect only to this device.
> 
> My next attempt was to write my own version of all basic plot functions (like plot, barplot etc.) adding a par() call within these functions.
> This works but only if I draw a single plot. As soon as I want to use mfrow or layout to draw multiple plots side by side into one device this version also does not work, since each of these functions will open a new drawing device by themselves.
> 
> 
> So, my question is;
> Is there any way to globally define parameters given to par() so that they apply to all plots in (at least) an entire R-session?

I haven't played with it, but setting a "plot.new" hook (or
"before.plot.new") might do it for you.  See ?plot.new.

It might be tricky, because some par() parameters (e.g. "mfrow")
shouldn't be called before every plot.  You'd have to look at
par("mfrow") to decide whether to call it or not.

Duncan Murdoch



More information about the R-help mailing list