、私はパーを()いくつかのように見えるrecordPlot()は最初のプロットのpar()とlayout()をどこに保存しますか?以下の記録のプロットで
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. notice no par() nor layout() before the first call to plot.new()
recorded = recordPlot()
lapply(recorded[[1]], "[[", 1)
# as a result, the following creates one plot per page, not 3 on the same page:
lapply(recorded[[ 1 ]] , function(x) { do.call(x[[ 1 ]] , as.list(x[[ 2 ]])) })
は、おそらくこれは、recorded[[ 2 ]]
でエンコードされた最初のplot.new()の呼び出しの前に設定レイアウトを構築し、設定する命令を見つけることができませんエンコードされた生データの種類?もしそうなら、最初のプロットの前にどのようにして私の指示をつかむことができますか?
警告:汚れたハック。
あなたが命令リストで初期状態をエンコードしたい場合は、ここに方法は次のとおりです。あなたはおそらくrecorded[[2]]
に何があるかについての正しい
tryCatch(dev.off() , error = function(e) {})
plot.new()
par(new = TRUE)
originalLayoutFunction = graphics:::layout
graphicsEnvironment = as.environment("package:graphics")
newLayoutFunction = function(...)
{
originalLayoutFunction(...)
par(mfg = c(1 , 1))
}
unlockBinding("layout" , env = graphicsEnvironment)
assign("layout" , newLayoutFunction , envir = graphicsEnvironment)
lockBinding("layout" , env = graphicsEnvironment)
tryCatch(YOUR_PLOT_CALL_HERE , finally =
{
unlockBinding("layout" , env = graphicsEnvironment)
assign("layout" , originalLayoutFunction , env = graphicsEnvironment)
lockBinding("layout" , env = graphicsEnvironment)
})
recordedPlot = recordPlot()
dev.off()
私はこれを恐れていました!それは非常にうまく動作するので、あまりにも悪い。欠落しているのは初期状態だけです。ありがとう、ジョシュ! – SFun28
私はRを最初のレイアウト/ parを命令リストに含めることをだます方法があると思います。問題はlayout()が次のプロットを新しいページにプロットさせることです。したがって、プロットを保存する前に、次のことができます:plot.new(); par(new = TRUE); (手を振って)レイアウト呼び出しを傍受し、par(mfg = c(1,1))を呼び出してグラフィックス:::レイアウト(...)の考えをしますか? – SFun28
は上記の解決策を掲載しました。 – SFun28