alirazi
alirazi

Reputation: 161

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))
      

Upvotes: 0

Views: 43

Answers (1)

scott.pilgrim.vs.r
scott.pilgrim.vs.r

Reputation: 507

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

Upvotes: 1

Related Questions