我正在尝试使用 .png 设备或 .pdf 设备将多个数据面板和 1 个绘图导出为单个图像,但没有取得任何成功。我可以使用 R native 绘图设备在 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
最佳答案
如果在打开图形设备后将调用移至 par
或 layout
,它应该可以正常工作。
png(file='plot2.png')
par(mfrow= c(3, 1))
curve(dnorm, -3, 4)
textplot(testMat)
textplot(testMatDF)
dev.off()
关于r - 将多个绘图和数据面板导出到 *.png(在 R 中使用布局()样式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13829365/