4

我正在尝试使用 .png 设备或 .pdf 设备将多个数据面板和 1 个绘图导出为单个图像,但我没有遇到任何成功。我可以使用 R 原生绘图设备在 R 中生成我想要的图像,但是当我尝试直接生成相同的图像时,我得到了我没有预料到的结果。

这是我的示例代码

testMat <- matrix(1:20, ncol = 5)##  create data
testMatDF <- as.data.frame(testMat)
names(testMatDF) <- c("Hey there", "Column 2", 
         "Some * Symbols", "And ^ More", 
         "Final Column")
rownames(testMatDF) <- paste("Group", 1:4)

library(gplots) ##  gplots needed for textplot()
layout(matrix(c(1, 1, 2, 3, 3, 3),  2, 3, byrow = TRUE))
curve(dnorm, -3, 4)
textplot(testMat)
textplot(testMatDF)
##  produces what I want within R

layout(matrix(c(1, 1, 2, 3, 3, 3),  2, 3, byrow = TRUE))
png(file='plot1.png')
curve(dnorm, -3, 4)
textplot(testMat)
textplot(testMatDF)
dev.off()
##  only the last function texplot(testMatDF) gets output, not what I anticipated

我也尝试过mfrow()图形参数但没有成功。

par(mfrow= c(3, 1))
png(file='plot2.png')
curve(dnorm, -3, 4)
textplot(testMat)
textplot(testMatDF)
dev.off()
##  only the last function texplot(testMatDF) gets output
4

1 回答 1

16

如果您将呼叫移至parlayout在打开图形设备之后,它应该可以正常工作。

png(file='plot2.png')
par(mfrow= c(3, 1))
curve(dnorm, -3, 4)
textplot(testMat)
textplot(testMatDF)
dev.off()
于 2012-12-11T22:17:30.017 回答