Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color scheme in corrplot

I am using corrplot in R to visualise a correlation-coefficient matrix as follows.

library(corrplot) 
library(datasets)
corrplot(abs(cor(mtcars)), method="color", tl.pos="n", cl.lim = c(0,1))

enter image description here

The default colour scheme is blue-based. However, I would like to change it to red-based. I know I need to use colorRampPalette to specify colours I want. However, I could not figure out what colour codes to use. Could anyone help me with this, please?

Thank you!

like image 882
LaTeXFan Avatar asked Jun 09 '15 22:06

LaTeXFan


People also ask

How do I change the color of a correlation matrix in python?

This can be done using Matplotlib Colormaps, which can be added in the function matshow with the argument cmap=plt. get_cmap(name) .

What correlation does Corrplot use?

[ R , PValue ] = corrplot( Tbl ) plots the Pearson's correlation coefficients between all pairs of variables in the table or timetable Tbl , and also returns tables for the correlation matrix R and matrix of p-values PValue .

Is Corr false?

corr is FALSE and corr is a non-negative or non-positive matrix, the default value will be COL1(YlOrBr,200); otherwise (elements are partly positive and partly negative), the default value will be COL2(RdBu,200). be c(-1,1) when is.


1 Answers

If you want to use red, you can define your own colorRampPalette as you've alread mentioned. Just note that the plot seems to set the range of colors from -1 to 1 (even if you adjust the cl.lim value). Thus you still need to define colors for the -1 to 0 range in your ramp. For example

corrplot(abs(cor(mtcars)), method="color", tl.pos="n", 
    cl.lim=c(0,1), col=colorRampPalette(c("blue","white","red"))(200))

will produce

enter image description here

and even though we defined "blue" in the color palette, it doesn't show up because we limited the color bar to values greater than 1.

This "unused" part of the color gradient cab be seen with the original version as well if you take out cl.lim

corrplot(abs(cor(mtcars)), method="color", tl.pos="n")

enter image description here

like image 72
MrFlick Avatar answered Sep 25 '22 23:09

MrFlick