Correlation plot
0
1
Entering edit mode
6 weeks ago
Rob ▴ 60

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.  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 • 527 views
0
Entering edit mode

First: The image link is broken.

Second:

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.

0
Entering edit mode

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

0
Entering edit mode

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

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.

0
Entering edit mode

Agree. SVG is an awesome format too.

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.

2
Entering edit mode

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