I am using corrplot
library to plot correlation matrices in this manner :
library(corrplot)
car_matrix <- cor(mtcars, use = "pairwise.complete.obs", method = "pearson")
png("Cars matrix.png", width = 1800, height = 1800, res = 300)
corrplot(car_matrix, method = "number", type = "upper",
col = RColorBrewer::brewer.pal(n = 8, name = "Greys"), tl.col = "black",
number.cex = 0.75, tl.srt = 0)
dev.off()
I use tl.srt = 0
parameter so that all the labels face upwards. Although the orientation is then corrected, there is no longer any spacing between top labels and the matrix (see image).
I tried to modify the spacing using tl.offset = 1
, which adds spacing to both top and left labels. But since left labels already have default spacing, tl.offset = 1
creates excessive spacing for them.
I can't find a parameter in corrplot
that allows to choose the spacing for top/left labels independently. Is there any other way to do so?
You could add a break to each name of the matrix to add some space like this:
data("mtcars")
library(corrplot)
library(RColorBrewer)
car_matrix <- cor(mtcars, use = "pairwise.complete.obs", method = "pearson")
colnames(car_matrix) <- paste0(colnames(car_matrix), "\n")
png("Cars matrix.png", width = 1800, height = 1800, res = 300)
corrplot(car_matrix, method = "number", type = "upper",
col = brewer.pal(n = 8, name = "Greys"), tl.col = "black",
number.cex = 0.75, tl.srt = 0)