Search code examples
rmatrixr-corrplot

How to include p-vlaues from a different matrix and change the size of circles/squares in corrplot?


Users,

I have two matrices "mm" and "mpm" of same size. The "mm" matrix contains pre-computed spearman's-rho correlation values and the "mpm" matrix contains the p-value corresponding to the correlation values.

> mm[1:5,1:5]
                          X572413     X573110    X358104     X570507
ENSG00000138755        -0.3197926  0.04386737 -0.3789759 -0.33553003
ENSG00000024048        -0.3596203  0.07819836 -0.4008268 -0.50528885
ENSG00000128849         0.2348660 -0.04513889  0.2273856  0.06665028
ENSG00000163827         0.3971051 -0.16466158  0.1864152  0.16520154
ENSG00000154451        -0.2899219 -0.03560250 -0.3721475 -0.36401305
                    X361966
ENSG00000138755 -0.08492661
ENSG00000024048 -0.35552037
ENSG00000128849  0.15638211
ENSG00000163827  0.13412548
ENSG00000154451 -0.10718324

> mpm[1:5,1:5]
                          X572413 X573110 X358104 X570507 X361966
ENSG00000138755             0.161   0.835   0.078   0.132   0.720
ENSG00000024048             0.118   0.705   0.078   0.028   0.114
ENSG00000128849             0.304   0.849   0.324   0.771   0.485
ENSG00000163827             0.086   0.475   0.430   0.494   0.548
ENSG00000154451             0.200   0.881   0.081   0.108   0.646

I want the p-values from the "mpm" to be plotted on the cells. And when I use the following code:

> corrplot(mm, is.corr = FALSE, method = "circle", p.mat = mpm[[1]], insig = "p-value", sig.level=-1)

I get this this error:

Error in ind[, 2] : incorrect number of dimensions

Can anyone help me with this ? Also, is it possible to alter the size of the cells based on p-values ? Thanks in advance for any help.


Solution

  • You need to convert mm and mpm to matrix.

    library(corrplot)
    corrplot(as.matrix(mm), is.corr = FALSE, method = "circle", 
             p.mat = as.matrix(mpm), insig = "p-value", sig.level=-1)
    

    enter image description here