Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to make an asymmetric coloured correlation matrix plot in R?

I’d like to make a colored asymmetric correlation matrix in R. Essentially, it’ll be a 4 by 6 correlation matrix (that looks something like the plots here). I have simulated some data here as an example data set:

dat <- data.frame(col1 = sample(0:3, 10, replace = TRUE),
                  col2 = sample(0:3, 10, replace = TRUE),
                  col3 = sample(0:3, 10, replace = TRUE),
                  col4 = sample(0:3, 10, replace = TRUE),
                  col5 = sample(0:3, 10, replace = TRUE),
                  col6 = sample(0:3, 10, replace = TRUE),
                  col7 = sample(0:3, 10, replace = TRUE),
                  col8 = sample(0:3, 10, replace = TRUE),
                  col9 = sample(0:3, 10, replace = TRUE),
                  col10 = sample(0:3, 10, replace = TRUE)) 

I want a coloured correlation plot that correlates col1 to col4 with col5 to col10. Does anyone know how to do this?

Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can make a matrix of the columns you want to cor. Maybe you want something like this:

dat.cor = cor(dat[,c(1,4)], dat[,5:10])

library(corrplot)
corrplot(as.matrix(dat.cor))

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading