David Winsemius
2010-May-14 19:51 UTC
[R] Are there better ways to save and restore par() settings
Some of the help page examples use the form:
opar <- par(<something>)
.....plotting activities...
par(opar)
This seems to "work" well, yet I have read in some places that it is
not the preferred method to keep you parameters from getting
corrupted. What is the preferred method?
A worked example from a recent posting with minor additions:
opar <- par(mar=c(3,5,0,5))
layout(rbind(c(4,1,1,5), c(2,2,3,3)), widths=c(1,1,1,1),
heights=c(.75,2.25))
barplot(0,0, axes=FALSE)
legend(x=0.5, y=0, legend=c("Example 1", "Example
2"),
pch=c(1,2), cex=1.5, xjust=1, yjust=0.5, bty="n")
plot(1:10,1:10, pch=1)
plot(1:20,1:20, pch=2)
par(opar)
--
David Winsemius, MD
West Hartford, CT
Duncan Murdoch
2010-May-14 21:45 UTC
[R] Are there better ways to save and restore par() settings
On 14/05/2010 3:51 PM, David Winsemius wrote:> Some of the help page examples use the form: > > opar <- par(<something>) > .....plotting activities... > par(opar) > > This seems to "work" well, yet I have read in some placesPlease include commented, retrievalbe citations for "some places".> that it is > not the preferred method to keep you parameters from getting > corrupted. What is the preferred method? > >The above, with the restore wrapped in on.exit(), as your sources should have said. Duncan Murdoch> A worked example from a recent posting with minor additions: > > opar <- par(mar=c(3,5,0,5)) > layout(rbind(c(4,1,1,5), c(2,2,3,3)), widths=c(1,1,1,1), > heights=c(.75,2.25)) > barplot(0,0, axes=FALSE) > legend(x=0.5, y=0, legend=c("Example 1", "Example 2"), > pch=c(1,2), cex=1.5, xjust=1, yjust=0.5, bty="n") > plot(1:10,1:10, pch=1) > plot(1:20,1:20, pch=2) > par(opar) > >