scien
scien

Reputation: 13

How to remove significance stars from chart.correlation function

I'm using the performance analytics chart.correlation program for 13 variables. I want to remove the significance stars from the upper quadrant.

I have tried using the ... and then adding "stars = FALSE" and other combinations based on reading what dependencies this package uses. This is a basic question that if answered will teach myself and others how to properly look up dependencies and how to change them in R packages.

library(PerformanceAnalytics)
my_data <- mtcars[, c(1,3,4,5,6,7)]
chart.Correlation(my_data, histogram = TRUE, pch = 19)

As expected there are bright red stars for significant p-values. Any help in making them disappear is appreciated.

Upvotes: 1

Views: 1309

Answers (1)

lroha
lroha

Reputation: 34501

If you look at the code for chart.Correlation you can see that the stars are generated via symnum(). You can create a copy of the function and comment this and the call to text() that places them out.

chart.Correlation.nostars <- function (R, histogram = TRUE, method = c("pearson", "kendall", 
                                          "spearman"), ...) 
{
  x = checkData(R, method = "matrix")
  if (missing(method)) 
    method = method[1]
  panel.cor <- function(x, y, digits = 2, prefix = "", 
                        use = "pairwise.complete.obs", method = "pearson", 
                        cex.cor, ...) {
    usr <- par("usr")
    on.exit(par(usr))
    par(usr = c(0, 1, 0, 1))
    r <- cor(x, y, use = use, method = method)
    txt <- format(c(r, 0.123456789), digits = digits)[1]
    txt <- paste(prefix, txt, sep = "")
    if (missing(cex.cor)) 
      cex <- 0.8/strwidth(txt)
    test <- cor.test(as.numeric(x), as.numeric(y), method = method)
    # Signif <- symnum(test$p.value, corr = FALSE, na = FALSE, 
    #                  cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c("***", 
    #                                                                           "**", "*", ".", " "))
    text(0.5, 0.5, txt, cex = cex * (abs(r) + 0.3)/1.3)
    # text(0.8, 0.8, Signif, cex = cex, col = 2)
  }
  f <- function(t) {
    dnorm(t, mean = mean(x), sd = sd.xts(x))
  }
  dotargs <- list(...)
  dotargs$method <- NULL
  rm(method)
  hist.panel = function(x, ... = NULL) {
    par(new = TRUE)
    hist(x, col = "light gray", probability = TRUE, 
         axes = FALSE, main = "", breaks = "FD")
    lines(density(x, na.rm = TRUE), col = "red", lwd = 1)
    rug(x)
  }
  if (histogram) 
    pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor, 
          diag.panel = hist.panel)
  else pairs(x, gap = 0, lower.panel = panel.smooth, upper.panel = panel.cor)
}


chart.Correlation.nostars(my_data)

enter image description here

Upvotes: 1

Related Questions