简体   繁体   English

如何在R中使用一个矩阵图整合两个矩阵的信息

[英]how to integrate the information of two matrices using one matrix plot in R

I have two matrices with the same dimension, column names and row names as shown below. 我有两个尺寸相同的矩阵,列名和行名如下所示。

data(mtcars)
M <- cor(mtcars)

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

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

I want to visualize the two matrices using one matrix plot, like 我想使用一个矩阵图可视化两个矩阵,例如

corrplot(M, method = "circle")

I want to make a new graph, in which the color of circle is based on the M matrix and the size based on the myMat matrix. 我想制作一个新图,其中圆圈的颜色基于M矩阵,大小基于myMat矩阵。 Is there a way to implement this in R language. 有没有一种方法可以用R语言实现。

Convert to long form and plot using ggplot: 转换为长格式并使用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("")

giving: 给予:

相关图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM