Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace "?" tiles in Corrplot

Tags:

r

r-corrplot

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.

like image 603
Jenks Avatar asked Nov 27 '17 16:11

Jenks


People also ask

How do you increase the size of a Corrplot?

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.

How do I change colors in Corrplot?

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.

Why are there question marks in my Corrplot?

The question marks denote that correlation is not defined in the given case due to insufficient amount of data.

What does Corrplot do in R?

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.


1 Answers

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

like image 131
Andrew Brēza Avatar answered Sep 27 '22 15:09

Andrew Brēza