Question

I want to draw a plot of correlations.

features = features[,-2]
features<- scale(features[2:ncol(features)],center=TRUE,scale=TRUE);
correlationmatrix <- cor(features)
corrplot(correlationmatrix, order = "hclust")

Until the 3rd line, everything works fine. When running corrplot(), I am getting:

Error in if (min(corr) < -1 - .Machine$double.eps || max(corr) > 1 + .Machine$double.eps) { : missing value where TRUE/FALSE needed

Was it helpful?

Solution

This is happening most likely because you are trying to plot a correlation matrix with missing values (NA).

Unfortunately corrplot does not deal with those properly...

You could plot the values yourself with some other technique.

Instead, I've however found a simple hack around this. I would not advise you to use it, for my data, it worked just fine. You'll also lose the ability to show the significant tests using corrplot.

M=cor(values,use="pairwise.complete.obs")
p = M
p[is.na(M)]=0.2 
p[is.na(M)==F]=0
M[is.na(M)]=0
corrplot(M, method="circle", is.corr=T, p.mat=p, sig.level=0.1, order = "FPC")

Unfortunately I am not able to post the resulting image as I just joined and don't have enough of this "stackoverflow reputation".

enter image description here

Hope it helps, you, or other person with the same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top