rggplot2visualizationcorrelationhmisc

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!


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