Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Change correlation matrix plot range to be from 0 to 1 – R

How can I change the plot range to be from 0 to 1 as the correlation matrix is always positive.

Script:

require(RColorBrewer)
library(corrplot)

set.seed(123)
data <- matrix(runif(100, min = 0, max = 1), nrow = 10)
df <- as.data.frame(data)
correlation_matrix <- cor(df)
correlation_matrix <- (correlation_matrix + 1) / 2
corrplot(correlation_matrix, method="circle",  col = rep(rev(brewer.pal(n=8, name="RdYlBu")), 2))
      

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This?

You can change the plot range using col.lim variable, with the min and max as a vector i.e. =c(min, max).

corrplot(col.lim=c(0,1),correlation_matrix, method="circle",  col = rep(rev(brewer.pal(n=8, name="RdYlBu")), 2))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading