我正在尝试使用.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
Run Code Online (Sandbox Code Playgroud)
我也尝试了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
Run Code Online (Sandbox Code Playgroud)
Jus*_*tin 14
如果您在打开图形设备时par或layout之后移动呼叫,它应该可以正常工作.
png(file='plot2.png')
par(mfrow= c(3, 1))
curve(dnorm, -3, 4)
textplot(testMat)
textplot(testMatDF)
dev.off()
Run Code Online (Sandbox Code Playgroud)