taiyun / corrplot

A visual exploratory tool on correlation matrix
https://github.com/taiyun/corrplot
Other
318 stars 87 forks source link

Corrplot figure became unreadable #223

Closed teindor closed 3 years ago

teindor commented 3 years ago

Hi I love your package and used it quite a bit. Recently, the figure became unreadable such that it is aligned to the bottom right and one value obscure another. The code I used is the following: library(corrplot) library(RColorBrewer) M = cor(cor.p) M colnames(p.mat)= c("Exposure", "Fear", "Depression", "Anxiety", "Perceived Parental Support", "Parental Supervision", "Negative Life Events", "Parent's Anxiety", "Parent's Depression") rownames(p.mat)=c("Exposure", "Fear", "Depression", "Anxiety", "Perceived Parental Support", "Parental Supervision", "Negative Life Events", "Parent's Anxiety", "Parent's Depression")

cor.mtest <- function(cor.p, ...) { mat <- as.matrix(cor.p) n <- ncol(cor.p) p.mat<- matrix(NA, n, n) diag(p.mat) <- 0 for (i in 1:(n - 1)) { for (j in (i + 1):n) { tmp <- cor.test(cor.p[, i], cor.p[, j], ...) p.mat[i, j] <- p.mat[j, i] <- tmp$p.value } } colnames(p.mat) <- rownames(p.mat) <- colnames(cor.p) p.mat }

p.mat <- cor.mtest(cor.p) p.mat

cp = corrplot(M, method = "color", type = "lower", p.mat = p.mat, sig.level = 0.05, tl.col="black", addCoef.col = "black", number.cex=0.75, col = brewer.pal(n = 8, name = "PuOr"), insig = "blank")

The figure and data are enclosed

corr corrplot data.txt

taiyun commented 3 years ago

The names are too long. You can use short-length names and small parameter cex

teindor commented 3 years ago

I have used it before with even longer names with no problems

taiyun commented 3 years ago

Set number.cex=0.5, tl.cex = 0.8 and zoom large the plot.

taiyun commented 3 years ago

I can get a readable figure with the code below.

library(corrplot)
library(RColorBrewer)

x = mtcars[,1:9]
colnames(x) = 
  c("Exposure", "Fear", "Depression", "Anxiety",
    "Perceived Parental Support", "Parental Supervision",
    "Negative Life Events", "Parent's Anxiety", "Parent's Depression")
M = cor(x)

corrplot(M, method = "color", type = "lower")

corrplot(M, method = "color", type = "lower", p.mat = cor.mtest(x)$p, 
         sig.level = 0.05, tl.col="black", addCoef.col = "black", 
         number.cex=0.75, col = brewer.pal(n = 8, name = "PuOr"), insig = "blank")