单个变量中的 R 倍数图 [英] R Multiples plot in a single varible
问题描述
我有下一个代码:
par(mfrow=c(1,3))
plot(BCxyz[,1], BCxyz[,2], main="Bray-Curtis 1:2", pch=20, cex = 3, col=c("blue", "green", "red", "yellow")[Metadata$SampleType])
plot(BCxyz[,1], BCxyz[,3], main="Bray-Curtis 1:3", pch=20, cex = 3, col=c("blue", "green", "red", "yellow")[Metadata$SampleType])
plot(BCxyz[,2], BCxyz[,3], main="Bray-Curtis 2:3", pch=20, cex = 3, col=c("blue", "green", "red", "yellow")[Metadata$SampleType])
通过这种方式,我得到了一个包含 3 个图的图形,所以我只想将图形(其中包含 3 个图)添加到一个变量中,例如:
in this way I get a figure with 3 plots, so I just want to add the figure (with 3 plot in it) in a single variable, something like :
figure1 <- (mfrow=c(1,3)........)
每次我调用图 1 时,在一个图中打开 3 个图 !!!!!!
and each time that I call figure1, open 3 plot in a single figure !!!!
谢谢
推荐答案
您可以使用 recordPlot
保存当前绘图并稍后调用.
You can use recordPlot
to save the current plot and recall it later.
par(mfrow=c(1,3))
plot(1) ; plot(2); plot(3)
figure1 <- recordPlot()
# view then close the plot window, just to prove that redrawing it works
figure1 # redraws it when interactive on the console
replayPlot(figure1) # same thing
print(figure1) # indirect, calls replayPlot
最后两个命令在控制台上具有相同的结果,但是如果您要以编程方式重放"绘图(例如,在 {...}
代码块或函数中),你应该直接使用 replayPlot
函数.figure1
在控制台上单独工作的原因(没有 print
或 replayPlot
)是 figure1
是类"recordedplot"
,以及 base-R grDevices::print.recordedplot
S3 方法直接调用 replayPlot
.
The last two commands have the same result on the console, but if you are going to "replay" the plot programmatically (e.g., within {...}
code-blocks or functions), you should use the replayPlot
function directly. The reason just figure1
works by itself on the console (no print
or replayPlot
) is that figure1
is of class "recordedplot"
, and the base-R grDevices:::print.recordedplot
S3 method calls replayPlot
directly.
这篇关于单个变量中的 R 倍数图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!