rggcorrplot

Show asterisk for significant p values in ggcorrplot


I wanted to ask is it possible to customize the p value representation in ggcorrplot such that instead of having insignificant correlations marked with a cross, the significant p values are marked with an asterisk instead? Which would hopefully look something like so:

enter image description here


Solution

  • Update: So I decided to look at the source code and tinkered a bit with it to produce the format I wanted to achieve. If you copy the whole code for the ggcorrplot() function, then on line 215 the original code is:

    p.mat <- subset(p.mat, p.mat$value > sig.level)

    Substitute this with:

    p.mat <- subset(p.mat, p.mat$value <= sig.level & p.mat$value != 0)

    The != 0 part is assuming you would choose the full correlation plot and is there to prevent the diagonal in the middle from having the asterisk and I believe no p value should practically be 0 so it should be fine.

    Then on line 295 I added the position argument inside the function:

    # matrix cell glyphs
      if (!is.null(p.mat) & insig == "pch") {
        p <- p + ggplot2::geom_point(
          data = p.mat,
          mapping = ggplot2::aes_string(x = "Var1", y = "Var2"),
          shape = pch,
          size = pch.cex,
          color = pch.col,
          position = position_nudge(x=0.35,y=0.16)
        )
      }
    

    The original would look something like: enter image description here

    While the modified one would be something like: enter image description here Of course, depending on visual preference, the nudge can be customized through the x and y argument. Then in the function, just choose pch = 8 (this is the asterisk) and pch.cex = 1 (size of asterisk) and that should basically achieve the objective of showing asterisk for significant correlations instead of showing crosses for insignificant correlations. Hopefully it can be of use in the future!