[R] reset par() within plot layout

Peter Ehlers ehlers at ucalgary.ca
Fri Oct 23 17:15:18 CEST 2009



Janke ten Holt wrote:
> 
> Tom Gottfried wrote:
>> Janke,
>>
>> Janke ten Holt schrieb:
>>> 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)
>> look at par.ini: it's a list with all the argument-value pairs for par(). You might be able to solve
>> your problem by removing the appropriate elements from par.ini before calling par(par.ini). Do the
>> following to look which ones need to be kept for the layout:
>>
>> par()
>> layout(matrix(1:2, nr=2))
>> par()
>>
>> Tom
>>
>>> 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.
> 
> Yes, that had occured to me too. So I tried:
> 
> layout(matrix(1:2, nr=2))
> par(no.readonly=TRUE)
> plot(1:10)
> par(no.readonly=TRUE)
> 
> This has differences in
> fig
> mfg
> usr
> xaxp
> yaxp
> 
> But even keeping these back does not solve my problem. So I figured
> there must be something else going on that I am unaware of...
> 

I think that what you want is

  layout(matrix(1:2, nr=2))
  opar <- par(col="red")
  plot(1:100)
  par(opar)
  plot(1:10)

-Peter Ehlers

> btw, your exact suggestion,
>> par()
>> layout(matrix(1:2, nr=2))
>> par()
> does not result in any differences.
> 
> ______________________________________________
> 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