Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With a bit of hackery you can do this in a very similar R package, <code>corrgram</code>. This one allows you to easily define your own panel functions, and helpfully makes theirs easy to view as templates. Here's the some code and figure produced:</p> <pre><code>set.seed(42) library(corrgram) # This panel adds significance starts, or NS for not significant panel.signif &lt;- function (x, y, corr = NULL, col.regions, digits = 2, cex.cor, ...) { usr &lt;- par("usr") on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) results &lt;- cor.test(x, y, alternative = "two.sided") est &lt;- results$p.value stars &lt;- ifelse(est &lt; 5e-4, "***", ifelse(est &lt; 5e-3, "**", ifelse(est &lt; 5e-2, "*", "NS"))) cex.cor &lt;- 0.4/strwidth(stars) text(0.5, 0.5, stars, cex = cex.cor) } # This panel combines edits the "shade" panel from the package # to overlay the correlation value as requested panel.shadeNtext &lt;- function (x, y, corr = NULL, col.regions, ...) { if (is.null(corr)) corr &lt;- cor(x, y, use = "pair") ncol &lt;- 14 pal &lt;- col.regions(ncol) col.ind &lt;- as.numeric(cut(corr, breaks = seq(from = -1, to = 1, length = ncol + 1), include.lowest = TRUE)) usr &lt;- par("usr") rect(usr[1], usr[3], usr[2], usr[4], col = pal[col.ind], border = NA) box(col = "lightgray") on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r &lt;- formatC(corr, digits = 2, format = "f") cex.cor &lt;- .8/strwidth("-X.xx") text(0.5, 0.5, r, cex = cex.cor) } # Generate some sample data sample.data &lt;- matrix(rnorm(100), ncol=10) # Call the corrgram function with the new panel functions # NB: call on the data, not the correlation matrix corrgram(sample.data, type="data", lower.panel=panel.shadeNtext, upper.panel=panel.signif) </code></pre> <p><img src="https://i.stack.imgur.com/JcuL8.png" alt="enter image description here"></p> <p>The code isn't very clean, as it's mostly patched together functions from the package, but it should give you a good start to get the plot you want. Possibly you can take a similar approach with the <code>corrplot</code> package too.</p> <p><strong>update:</strong> Here's a version with stars and cor on the same triangle:</p> <pre><code>panel.shadeNtext &lt;- function (x, y, corr = NULL, col.regions, ...) { corr &lt;- cor(x, y, use = "pair") results &lt;- cor.test(x, y, alternative = "two.sided") est &lt;- results$p.value stars &lt;- ifelse(est &lt; 5e-4, "***", ifelse(est &lt; 5e-3, "**", ifelse(est &lt; 5e-2, "*", ""))) ncol &lt;- 14 pal &lt;- col.regions(ncol) col.ind &lt;- as.numeric(cut(corr, breaks = seq(from = -1, to = 1, length = ncol + 1), include.lowest = TRUE)) usr &lt;- par("usr") rect(usr[1], usr[3], usr[2], usr[4], col = pal[col.ind], border = NA) box(col = "lightgray") on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r &lt;- formatC(corr, digits = 2, format = "f") cex.cor &lt;- .8/strwidth("-X.xx") fonts &lt;- ifelse(stars != "", 2,1) # option 1: stars: text(0.5, 0.4, paste0(r,"\n", stars), cex = cex.cor) # option 2: bolding: #text(0.5, 0.5, r, cex = cex.cor, font=fonts) } # Generate some sample data sample.data &lt;- matrix(rnorm(100), ncol=10) # Call the corrgram function with the new panel functions # NB: call on the data, not the correlation matrix corrgram(sample.data, type="data", lower.panel=panel.shadeNtext, upper.panel=NULL) </code></pre> <p><img src="https://i.stack.imgur.com/gjpl3.png" alt="enter image description here"></p> <p>Also commented out is another way of showing significance, it'll bold those below a threshold rather than using stars. Might be clearer that way, depending on what you want to show. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload