[R] Plotcorr: colour the ellipses to emphasize the differences

Duncan Murdoch murdoch at stats.uwo.ca
Sun Oct 17 15:34:03 CEST 2004


On Sun, 17 Oct 2004 02:51:58 +0200, "Gorjanc Gregor"
<Gregor.Gorjanc at bfro.uni-lj.si> wrote:

>Hello R users!
>
>I began with R and I must say that it is really nice. I have data with a lot of variables
>and have a problem to extract the pattern from correlation matrix. So I tried with plotcorr
>and it went fine. While I was reading the help page of this function, I found that ellipse
>display can be even better with use of different colors (the code is bellow). However I have
>a problem to understand the process of generating the colors. The function cm.colors() with argument 11 produces scale of colors with 11 points. What is the meaning of [5*xc + 6])?

xc is the vector of correlations (which presumably lie between -1 and
1, so 5*xc + 6 is an index into the vector of colours which lies
between 1 and 11.


> If I ommit this part from the code, I see that ellipses bellow diagonal do not have the same color as above the diagonal. In given example numbers 5 and 6 are given (I think so) since there are 11 variables in dataset mtcars. 
>
>How can one use this setup for other datasets? For example I have a dataset with 15 variables.

Just the same way.  The choice of how many colours to display is
orthogonal to the size of the matrix.
>
>I would also like to know if it is possible to use some other scale of colors instead of cm.colors, rainbow, heat.colors, terrain.colors, topo.colors. I would like to have positive correlations in blue and nagative ones in red spectrum of colors. Is it possible?

The source of cm.colors is visible (just type "cm.colors" and it will
be printed).  You could write your own function to change the scale to
blue through red instead of cyan through magenta by changing a few
constants in that function.

I think it would be useful to have a general function that did what
cm.colors does but for other paths through colour space, but I've
never written one (or done a thorough search to see if someone else
has.)

Duncan Murdoch




More information about the R-help mailing list