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.
The solution for this was duplicate the color range, so, the get the second half...
I encountered a similar problem but had mostly very high correlations. That made it hard to distinguish between different points without defining a lot of unused colors in my palette.
My solution was to rescale my correlations to the range
(-1, 1)
(which is the range assumed bycorrplot
) prior to plotting:This way the entire distribution of values can again be nicely distinguished using my colors of choice
col
.