2016-09-15 108 views
0

我有兩個矩陣具有相同的維度,列名和行名稱如下所示。如何整合兩個矩陣的信息使用一個矩陣圖R

data(mtcars) 
M <- cor(mtcars) 

myMat<-matrix(runif(11*11), ncol=11) 

colnames(myMat) <- colnames(M) 
rownames(myMat) <- rownames(M) 

我希望顯示使用一個矩陣圖兩個矩陣,如

corrplot(M, method = "circle") 

我想使一個新的圖,其中,圓的顏色是基於M矩陣和大小基於myMat矩陣。 有沒有辦法在R語言中實現這一點。

回答

1

轉換爲長型和情節使用ggplot:

library(ggplot2) 
long <- cbind(as.data.frame.table(M, responseName = "cor"), myMat = c(myMat)) 

ggplot(long, aes(Var1, Var2, col = cor, size = myMat)) + 
    geom_point() + 
    scale_colour_gradient(low = "red", high = "blue") + 
    xlab("") + 
    ylab("") 

,並提供:

correlation plot

+0

謝謝,這正是我想要的。 –