Hi friends

I used the following code to draw a correlation plot. (corrplot package)

  1. How can I show p-value as size of circle in the plot?
  2. How can I add a legend showing size of circles related to p-value (the larger the p-value the smaller the circle size)
  3. how can I clean the circles, as in the image edge of circles' color are not very clean and clear.

here is the correlation plot

ibb.co/VL2SZF5

code :

mat <- read.csv("Correlation_plot.csv", header = T)
# mat : is a matrix of data
# ... : further arguments to pass to the native R cor.test function
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
}
# matrix of the p-value of the correlation
p.mat <- cor.mtest(mat)
write.csv(p.mat, "p_value_corr_plot.csv")

and plot:

M <-cor(mat)
corrplot(M, type="upper", order="hclust", col=col, cl.cex = 1, tl.cex = 1,
         tl.col = "black", tl.srt = 45, mar = c(0, 0, 0, 0),
         p.mat = p.mat)



Source link