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

Martin Batholdy batholdy at googlemail.com
Mon Jul 20 18:11:18 CEST 2015


Thanks for the reply.

It works fine for a single plot-call.
But as soon as I call layout() before plotting I again run into the problem that plots are not drawn into one graphic device but another one is opened for the second plot-call.


see here;


setHook("plot.new", function() 
	par(bty='n', 
		cex=0.8,
		las=1, 
		ann=F, 
		lwd=2, 
		mar=c(5, 4, 2, 1), 
		oma=c(0,0,0,0), 
		pch=19, 
		xpd=T, 
		cex.axis=0.85, 
		mgp=c(2.5, 0.72, 0),
		tcl=-0.4
		)
)


layout(matrix(1:2, 1, 2, byrow=T))

plot(c(1,2,3))
plot(c(3,2,1))






On 20 Jul 2015, at 17:48 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

> 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