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.
The correlation coefficient value size in correlation matrix plot created by using corrplot function ranges from 0 to 1, 0 referring to the smallest and 1 referring to the largest, by default it is 1. To change this size, we need to use number. cex argument.
To change the color code of corrplot, we can use colorRampPalette function inside corrplot function. We can provide different colors in colorRampPalette that we want to display in the corrplot.
The question marks denote that correlation is not defined in the given case due to insufficient amount of data.
R package corrplot provides a visual exploratory tool on correlation matrix that supports automatic variable reordering to help detect hidden patterns among variables. corrplot is very easy to use and provides a rich array of plotting options in visualization method, graphic layout, color, legend, text labels, etc.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With