Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R corrplot: how to modify the number of displayed digits for the p-value?

I am using the corrplot() function in R to create a correlation heatmap. I want to display the p-values for the correlations.

corrplot(as.matrix(M2), method="color", p.mat = as.matrix(p_mat2), sig.level=0.05,  tl.cex=font_size, insig="p-value")

enter image description here

I would like to display really small p-values in some cases, and show more than two digits. I saw that there is the number.digits parameter, however this seems to be only for the display of the correlation coefficient. Is there any setting to control the number of digits for the displayes p-values?

like image 843
aldorado Avatar asked Sep 02 '25 10:09

aldorado


2 Answers

The below works for me:

library(corrplot)

M = cor(mtcars)

corrplot(M, method = 'number', number.digits = 3) # colorful number

For more details check: https://github.com/taiyun/corrplot/blob/master/R/corrplot.R

like image 173
psalmbab Avatar answered Sep 04 '25 01:09

psalmbab


In corrplot each row and column is positioned on a grid and the distance between the cells is equal to 1. This means that you can add any text you want with the call to text() function. Here is an example:

# generate M2 and p_mat2 since they were not provided
M2     <- matrix(runif(10), nrow=2)
p_mat2 <- matrix(runif(10, min=0, max=0.1), nrow=2)

# call corrplot and add p-values using text()
corrplot(as.matrix(M2), method="color", sig.level=0.05,  tl.cex=1)
text(col(M2), row(M2), round(p_mat2, 5), cex=0.5)

Result:

corrplot_with_pvalues

like image 29
Karolis Koncevičius Avatar answered Sep 04 '25 00:09

Karolis Koncevičius