4

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?

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
aldorado
  • 4,394
  • 10
  • 35
  • 46

2 Answers2

1

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

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
  • It seems `text` starts plotting from the bottom left corner instead of top left, so `y` coordinates should be flipped, i.e., replaced from `row(M2)` for something like `nrow(M2)+1-row(M2)` – Jonh Smith Jun 26 '20 at 16:03
1

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

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
psalmbab
  • 11
  • 2