问题描述
是否可以在单个图形中绘制多个corrplot
图形?
Is it possible to plot several corrplot
graphs in a single graph?
可复制的示例:
library(corrplot)
data(mtcars)
M <- cor(mtcars)
col1 <- colorRampPalette(c("#7F0000","red","#FF7F00","yellow","white", "cyan", "#007FFF", "blue","#00007F"))
corrplot(M, method="color", col=col1(20), cl.length=21,order = "AOE", addCoef.col="grey")
corrplot(M, method="square", col=col1(200),order = "AOE")
corrplot(M, method="ellipse", col=col1(200),order = "AOE")
corrplot(M, method="shade", col=col1(20),order = "AOE")
我想知道是否有类似于多重绘图函数"的函数适合于此目的.我希望所有这些corrplots在同一输出中.
I am wondering if there is a function similar to "Multiple plot function" suitable for this purpose. I want all these corrplots in the same output.
推荐答案
可以.只需在脚本中使用par(mfrow=c(2,2))
:
Sure it is. Just use par(mfrow=c(2,2))
in your script:
library(corrplot)
data(mtcars)
M <- cor(mtcars)
col1 <- colorRampPalette(c("#7F0000","red","#FF7F00","yellow","white", "cyan", "#007FFF", "blue","#00007F"))
#this is my only addition
par(mfrow=c(2,2))
corrplot(M, method="color", col=col1(20), cl.length=21,order = "AOE", addCoef.col="grey")
corrplot(M, method="square", col=col1(200),order = "AOE")
corrplot(M, method="ellipse", col=col1(200),order = "AOE")
corrplot(M, method="shade", col=col1(20),order = "AOE")
您已完成:
请注意,在par(mfrow=c(2,2))
中,第一个2
代表行,第二个2
代表列.您可以将其更改为任何您喜欢的.我选择这样显示您的4个图,因为它看起来不错,但是如果您愿意,可以使用par(mfrow=c(1,4))
(1行4列)将它们全部放在一行中.
Note that in par(mfrow=c(2,2))
the first 2
represents the rows and the second 2
represents the columns. You can change that to whatever you like. I chose to have your 4 graphs presented like that because it looks nice, but you could ,say, have them all in one row if you like by using par(mfrow=c(1,4))
(1 row, 4 columns).
这篇关于在同一图中绘制多个Corrplot(R)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!