Correlation plot
0
1
Entering edit mode
2.9 years ago
Rob ▴ 170

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 test

https://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)
Correlation R corrplot • 3.0k views
ADD COMMENT
0
Entering edit mode

First: The image link is broken.

Second:

Read. The. Manual. Please.

ADD REPLY
0
Entering edit mode

Thanks Arsenal, I editted the plot link. Can you please take a look? I don't know why the circles are spotty in the edge.

ADD REPLY
0
Entering edit mode

That looks pretty simple. How are you rendering the plot?

ADD REPLY
0
Entering edit mode

I exported the plot as tiff /jpg/ copy & paste. All were the same

ADD REPLY
0
Entering edit mode

Show us the code you're using to export the plot as an image. TIFF should retain full resolution. Try saving it to a pdf/svg.

ADD REPLY
0
Entering edit mode

Agree. SVG is an awesome format too.

ADD REPLY
0
Entering edit mode

Actually, I do not use code for exporting the image. I just use export button in R, window in the right down. Even before exporting, the plot does not have resolution in the plot area of R studio.

ADD REPLY
2
Entering edit mode

It is expected that the within-window render resolution is lower. Use export functions.

ADD REPLY

Login before adding your answer.

Traffic: 2724 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6