r - 将多个绘图和数据面板导出到 *.png(在 R 中使用布局()样式)

标签 r plot

我正在尝试使用 .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

最佳答案

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

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/

相关文章:

regex - gsub:用正则表达式替换字符串替换正则表达式匹配

r - 点与线之间的差异

python - 散点图的矩阵元素

R - 解释 ggplot 中使用的变量中的下标

r - 如何修改这个相关矩阵图?

python - Matplotlib 实时 pyplot

r - 制作一个中心空心的圆形条形图(又名赛道图)

r - ggplot geom_text字体大小控制

r - 在ggplot2中添加大括号,然后使用ggsave

R 为每次调用函数创建一个向量