0
votes

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. Is there a way to implement this in R language.

1

1 Answers

1
votes

Convert to long form and plot using 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:

correlation plot