【问题标题】:how to integrate the information of two matrices using one matrix plot in R如何使用R中的一个矩阵图整合两个矩阵的信息
【发布时间】:2016-09-15 09:33:35
【问题描述】:

我有两个具有相同维度的矩阵,列名和行名如下所示。

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 语言实现。

【问题讨论】:

    标签: r matrix plot


    【解决方案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("")
    

    给予:

    【讨论】:

    • 谢谢,这正是我想要的。
    猜你喜欢
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多