Reputation: 743
Hi I have the next code:
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])
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)........)
and each time that I call figure1, open 3 plot in a single figure !!!!
Thanks
Upvotes: 1
Views: 239
Reputation: 160437
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
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.
Upvotes: 2