5
votes

I have a corrplot that has NA's in the correlation matrix. Corrplot replaces tiles that have NA in the correlation matrix with "?" (see below). Does anyone know a way to replace these tiles with another color, rather than the questions mark?

This code gives the following image:

corrplot(matrix(data = c(0.5,0.2,NA,NA, 0.7,0.5),nrow = 3, ncol = 2),method="shade",shade.col=NA, type = 'lower')

enter image description here

The lower left tile I would like to define as a color not in the correlation color palate.

3
Replace the NA values with 0s before plotting and they should become blank white tiles. - Zach
@Zach, that would put it on the same spectrum on the correlation palate which I don't want, would give the wrong message. - Jenks

3 Answers

9
votes

There are two arguments you can pass to corrplot() to determine how NA values should appear: na.label and na.label.col.

You can replace the ? with any one or two characters of text using na.label. Let's change it to NA.

library(corrplot)

# Add an NA column to mtcars
M <- cor(cbind(mtcars, NA))

corrplot(M, na.label = "NA")

NA for NA

You can also change the color of the message.

corrplot(M, na.label = "NA", na.label.col = "orange")

Orange NA

If you want to use a color instead of text for the NA boxes, set na.label to "square".

corrplot(M, na.label = "square", na.label.col = "orange")

Orange you glad I didn't say NA

2
votes

If you want to replace the fields for an empty value you could also label the values empty, e.g: corrplot(df, na.label = " ")

0
votes

Best option is corrplot(na.omit())