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')
The lower left tile I would like to define as a color not in the correlation color palate.
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")
You can also change the color of the message.
corrplot(M, na.label = "NA", na.label.col = "orange")
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")