2

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

Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89
tesgoe
  • 1,012
  • 3
  • 10
  • 19
  • 1
    Please give a sample of your data to make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – tonytonov Feb 27 '14 at 13:17

1 Answers1

8

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.

ManuelLevi
  • 358
  • 1
  • 4
  • 9