Suraj
Suraj

Reputation: 36597

Understanding par in recordedPlot() & display lists

I've recorded a plot created by a function. The function sets various par() values so that three charts can appear on the same page with various colors:

library( PerformanceAnalytics )
data( managers )

# write the plot to the open device
suppressWarnings(charts.RollingRegression(managers[, 1:6], managers[, 8, drop=FALSE], Rf = .04/12, colorset = rich6equal, legend.loc="topleft"))

# record = investigate the primitive calls
recorded = recordPlot()
lapply(recorded[[1]], "[[", 1 )

# show the last instruction - the par call that does most of the par work
recorded[[ 1 ]][[ 54 ]]

I don't understand how/why the last .Primitive call is "par" (and contains the bulk of the par values required to show three charts on the same page). This appears after the "plot.new" for the last/bottom chart (you can inspect the "title" to confirm). If the instructions are executed in-order, then the par() will be applied last and the layout will be all messed up. It doesn't seem like the instructions can be executed in reverse order because plot.new() is required.

I do not understand how replayPlot() reconstructs the plot with the correct par() settings. Could someone elaborate?

Upvotes: 1

Views: 326

Answers (1)

IRTFM
IRTFM

Reputation: 263461

If I had been writing recordPlot, I would have made an attempt to gather the existing par() setting at the point it was started so they could be restored (with a par() call) after exit and reentry.

Upvotes: 3

Related Questions