caijun / ggcorrplot2

Implementation of corrplot using ggplot2
MIT License
37 stars 11 forks source link

Could these text labels on the diagonal be Customized? #8

Open DickRLee opened 2 years ago

DickRLee commented 2 years ago

Thank you so much for such a detailed user guide, it is very helpful for beginners like me. I'm a microbial ecology researcher and often deal with longer microbiology terms. I like the lower triangle graph in your package, but the text labels on the diagonal in it don't perform very well when the words are very long. Is there any parameter that I can use to choose to hide the diagonal text labels or adjust their position? Thank you very much! https://github.com/caijun/ggcorrplot2/blob/master/figs/README-unnamed-chunk-2-6.png

LDSamson commented 2 years ago

I tried to implement changes to address this issue here. You can try this out locally by installing:

devtools::install_github("LDSamson/ggcorrplot2@improve_labels")

It is not perfect, but it has some changes so that longer labels are slightly better supported. The labels are rotated by default (which is also the default behavior of the original corrplot package). Some labels can still be cut off, especially the first ones on top. I tried to mitigate that to dynamically assign additional plot padding, based on label length.

library(ggcorrplot2)
data(mtcars)
library(psych)
ct <- corr.test(mtcars, adjust = "none")
corr <- ct$r
p.mat <- ct$p

# example long labels:
colnames(corr) <- paste0(colnames(corr), "longlabel", sep = "")
rownames(corr) <- colnames(corr)
ggcorrplot(corr, type = "lower")

long_lable_fig

What do you think @caijun ?

caijun commented 2 years ago

@LDSamson thanks for your implementation. I have merged your PR.

caijun commented 2 years ago

@DickRLee You may try the latest version of ggcorrplot2.