Search code examples
rr-corrplot

Unused argument - corrplot?


I am a novice at this. I wanted to create a correlation matrix using corrplot and used the following code:

 cor.mtest <- function(mat, ...) {
    mat <- as.matrix(mat)
    n <- ncol(mat)
    p.mat<- matrix(NA, n, n)
    diag(p.mat) <- 0
    for (i in 1:(n - 1)) {
        for (j in (i + 1):n) {
            tmp <- cor.test(mat[, i], mat[, j], ...)
            p.mat[i, j] <- p.mat[j, i] <- tmp$p.value
        }
    }
  colnames(p.mat) <- rownames(p.mat) <- colnames(mat)
  p.mat
}

        p.mat<-cor.mtest(dataset)

    corrplot(cor(dataset, use="complete.obs"), type="upper", order="hclust", 

    p.mat=p.mat, sig.level=0.1)

It's one I used before, but this time around I got an error message:

Error in corrplot(cor(dataset, use = "complete.obs"), type = "upper",  : 
  unused arguments (type = "upper", order = "hclust", p.mat = p.mat, sig.level = 0.01)

Any idea why that is and how I can fix it?


Solution

  • An unused argument error in R means that you are providing named arguments that do not match to the actual arguments of the function. This is generally caused by misspellings or accidental usage of similarly-named functions from different packages.

    It looks like the arguments being flagged in this case are for the corrplot function of the corrplot package. There are other corrplot functions from other packages, e.g. arm. Are you sure you loaded the right package?