Corrplot - Axis labels grouping help request

Hi everyone,

I am new to R and have some questions regarding the corrplot package. I am trying to create a visualization for a correlation matrix (50x50) with each block of 10 variables belonging to a certain group, resulting 5 main groups. I have attached an example of the matrix as it currently is.

As the axis labels are a bit difficult to read, I would like to add additional x- and y-axis labels grouping each block of variables to their respective group. For example, variables 1-10 belong to group A. I would therefore like A to be presented on the left side of the x-axis and the top of the y-axis so that the figure is more cohesive. I would like to do this for all 5 groups. Below is an example of the code I have used:

Corr <- read.csv(file.choose("Corr.csv"))
Corrmatrix <- as.matrix(Corr, row.names = 1)
library(corrplot)
corrplot(Corrmatrix, is.corr = FALSE, tl.cex = 0.5, method = "color", tl.col="black")

I have not yet found way to add extra labels grouping the variables and any help would be greatly appreciated!

Frankly, I am surprised this worked as well as it did.

library(corrplot)
#> Warning: package 'corrplot' was built under R version 3.5.3
#> corrplot 0.84 loaded
set.seed(5389)
x <- runif(2500, min = 0, max = 1)
CorrMat <- matrix(x, nrow = 50)
corrplot(CorrMat, is.corr = FALSE, tl.cex = 0.5, method = "color", tl.col="black")
text(x = rep(-5, 5), y = seq(5, 45, 10), labels = LETTERS[5:1])

Created on 2019-10-08 by the reprex package (v0.3.0.9000)

2 Likes

Hi FJCC,

Thank you so much for your reply, the code works for me! I have tried applying the same principle to the y-axis (as I need the same labels for both x- and y-axes) but I have not had much success.

Can you advise on how to have the same labels on the y-axis as well?

Here is an example of using mtext() and messing with the mar parameter of corrplot() to make enough margin around the plot to place the labels. mar is one of the many parameters that can be set with par() function. If you look in the help for that function, there is a small explanation. I cannot explain why I had to set the line argument of mtext to 4 in one case. I just kept incrementing it until I got what I wanted.

library(corrplot)
#> Warning: package 'corrplot' was built under R version 3.5.3
#> corrplot 0.84 loaded
set.seed(5389)
x <- runif(2500, min = 0, max = 1)
CorrMat <- matrix(x, nrow = 50)
corrplot(CorrMat, is.corr = FALSE, tl.cex = 0.5, method = "color", tl.col="black", 
         mar = c(1,1,1,1))
mtext(text = LETTERS[5:1], side = 2, line = 0, at = seq(5, 45, 10), las = 1 )
mtext(text = LETTERS[1:5], side = 1, line = 4, at = seq(5, 45, 10), las = 1 )

Created on 2019-10-08 by the reprex package (v0.3.0.9000)

2 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.