[R] reset par() within plot layout

Janke ten Holt j.c.ten.holt at rug.nl
Fri Oct 23 14:50:51 CEST 2009

OK, maybe I oversimplified the example, because you are of course correct...

I am working on a function, which I feed data to plot in layouts of
specified dimensions. I want to be able to set any par() variables for
each plot in the layout. Because the next plot does not know which par()
variables were changed in the previous plot, I want to reset all par()
variables after each plot, rather than simply change back one specific
par() variable.
So I really need to reset par() without 'messing with' my layout.

stephen sefick wrote:
> Maybe something like this?
> #Desired result is a layout of 2 plots: one red and one black
> par(mfrow=c(2,1))
> par(col="red")
> plot(1:100)
> par(col="black")
> plot(1:10)
> On Fri, Oct 23, 2009 at 7:26 AM, Janke ten Holt <j.c.ten.holt at rug.nl> wrote:
>> Dear list,
>> I would like to produce a matrix of plots, where par() is reset after
>> each plot (see below [simplified] example). When I use layout() to do
>> so, I seem to also reset the layout. I have not been able to figure out
>> how to prevent this from happening.
>> Any help is greatly appreciated!
>> Janke
>> Example code:
>> #Desired result is a layout of 2 plots: one red and one black
>> layout(matrix(1:2, nr=2))
>> par.ini <- par(no.readonly=TRUE)
>> par(col="red")
>> plot(1:100)
>> par(par.ini)
>> plot(1:10)
>> ------------------
>> Janke ten Holt
>> Dept. of Psychology/Sociology
>> University of Groningen, the Netherlands
>> ______________________________________________
>> R-help at r-project.org 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.

More information about the R-help mailing list