Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R corrplot colorlegend change range

I am trying to plot in R a correlation matrix using the corrplot package.
My problem is that the range of min and max correlation coefficients of the entire matrix is (-0.2,0.2). I plot the matrix with corrplot and I use a custom colorRampPalette, say

col1<-colorRampPalette(c('red','yellow','green','blue'))

for the colormap of the legend, so I set col=col1(10), and I set cl.lim=c(-0.2,0.2).

When I see the plot however the colorlegend appears from -0.2 to 0.2 but with just 2 colors, instead what I would like is a colorlegend with the entire spectrum of colors in 10 bins of the custom palette but in range (-0.2,0.2) so instead of having just 2 colors I will have 10 colors.

like image 270
cristis Avatar asked Oct 19 '22 18:10

cristis


1 Answers

The solution for this was duplicate the color range, so, the get the second half...

mypal = jet.colors(1000) # jet.colors from library(matlab)

color = c(mypal,mypal)

corrplot(M, col=color)
like image 164
DemetriusRPaula Avatar answered Oct 27 '22 00:10

DemetriusRPaula