Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some correlations are plotted in both blue and red #165

Closed
pelingul opened this issue May 9, 2021 · 3 comments
Closed

Some correlations are plotted in both blue and red #165

pelingul opened this issue May 9, 2021 · 3 comments
Labels

Comments

@pelingul
Copy link

pelingul commented May 9, 2021

CorrelationMatrixStudy2WesternSample  R R

I have noticed that some positive correlations between 0 and .30 are plotted in blue, while they should be plotted in red. I'm using this code:

CovidData <- read_spss(choose.files())
corrplot2 <- function(data,
                      method = "pearson",
                      sig.level = 0.05,
                      order = "original",
                      diag = FALSE,
                      type = "upper",
                      tl.srt = 90,
                      number.font = 1,
                      number.cex = .75,
                      cl.cex = 1,
                      tl.cex = 1,
                      mar = c(0, 0, 0, 0)) {
  library(corrplot)
  data_incomplete <- data
  data <- data[complete.cases(data), ]
  mat <- cor(data, method = method)
  cor.mtest <- function(mat, method) {
    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], method = method)
        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(data, method = method)

  col <- colorRampPalette(c("#4477AA", "#77AADD", "#FFFFFF", "#EE9988", "#BB4444"))
  corrplot(mat,
           method = "color", col = col(200), number.font = number.font,
           mar = mar, number.cex = number.cex, cl.cex = cl.cex, tl.cex = tl.cex,
           type = type, order = order,
           addCoef.col = "black", # add correlation coefficient
           tl.col = "black", tl.srt = tl.srt, # rotation of text labels
           # combine with significance level
           p.mat = p.mat, sig.level = sig.level, insig = "blank",
           # hide correlation coefficiens on the diagonal
           diag = diag
  )
}
corrplot2(
  data = CovidData,
  method = "pearson",
  sig.level = 0.05,
  order = "original",
  diag = FALSE,
  type = "upper",
  tl.srt = 45
)
@vsimko vsimko added the bug label May 10, 2021
@taiyun
Copy link
Owner

taiyun commented May 10, 2021

@pelingul you can try toget the correct plot by setting full_col = FALSE

@taiyun taiyun closed this as completed in 16c5ca7 May 10, 2021
@taiyun taiyun reopened this May 10, 2021
@taiyun
Copy link
Owner

taiyun commented May 10, 2021

Thanks.

I have removedfull_col and will update to CRAN soon.

@pelingul
Copy link
Author

Thank you very much @taiyun
It is fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants