corrplot
绘制相关矩阵,但不返回图形对象(grob)
我想在一个页面上绘制几个相关矩阵。对于普通图,我会使用grid.arrange
包中的gridExtra
。但是因为corrplot只打印并且没有返回对象,所以我看不到如何执行此操作。
是否有解决方法或更好的替代corrplot
?
答案 0 :(得分:11)
最近的gridGraphics
软件包可能会按照您的要求执行操作:将图表作为grob返回。
mat <- matrix(rnorm(100), ncol=10)
library(corrplot)
corrplot(cor(mat))
library(gridGraphics)
grab_grob <- function(){
grid.echo()
grid.grab()
}
g <- grab_grob()
library(gridExtra)
grid.newpage()
grid.arrange(g,g,g,g)
答案 1 :(得分:7)
旧备用par(mfrow=c(x, y))
,其中x
是您要绘制的行数,y
列数。然后它会在您调用图表时发布,然后向下发布。
par(mfrow = c(2, 2))
corrplot(cor(mat1))
corrplot(cor(mat2))
corrplot(cor(mat3))
corrplot(cor(mat4))
par(mfrow = c(1, 1)) #To clear layout
将绘制为
Mat1 | Mat2
-----------
Mat3 | Mat4
答案 2 :(得分:2)
不确定我的问题是否正确,但也许您正在寻找的内容很简单layout
?
mat <- matrix(rnorm(100), ncol=10)
layout(matrix(1:2))
corrplot(cor(mat))
corrplot(cor(mat))