r - 单个变量中的 R 倍数图
问题描述
嗨,我有下一个代码:
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 个图)添加到一个变量中,例如:
figure1 <- (mfrow=c(1,3)........)
每次我调用figure1时,在一个图中打开3个情节!!!!
谢谢
解决方案
您可以使用recordPlot
保存当前绘图并在以后调用它。
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
class "recordedplot"
,并且 base-R grDevices:::print.recordedplot
S3 方法直接调用replayPlot
。
推荐阅读
- python - 如何遍历 Azure DevOps Pipelines 中的 JSON 文件?
- mysql - 调用过程时“无效使用组函数”
- pagespeed - Pagespeed Insights(和引擎盖下的 Lighthouse)是否需要为 HTTPS URL 提供正确签名的 SSL 证书?
- powerquery - 在 Excel 中使用 python 自动化时,Power Query 数据连接丢失
- django-models - 如何覆盖 Wagtail StructBlock 中的验证器
- nginx - NGINX 作为反向代理的问题
- kotlin - jooq, simpleflatmapper, kotlin 映射
- spring-boot - 向 security.oauth2.jwt.Jwt 添加声明
- java - 如何在 sping boot 中提供音频文件
- cxf - Apache CXF 插件 3.3.12 和 3.4.5 不能在 Java 11 下运行?