Gorjanc Gregor
2004-Oct-17 00:51 UTC
[R] Plotcorr: colour the ellipses to emphasize the differences
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])? 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. 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? Thank you! # Colour the ellipses to emphasize the differences corr.mtcars <- cor(mtcars) ord <- order(corr.mtcars[1,]) xc <- corr.mtcars[ord, ord] plotcorr( xc, col=cm.colors(11)[5*xc + 6]) With regards, Lep pozdrav Gregor GORJANC
Uwe Ligges
2004-Oct-17 13:21 UTC
[R] Plotcorr: colour the ellipses to emphasize the differences
Gorjanc Gregor 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])? 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. > > 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?Have you looked at the RColorBrewer package? Uwe Ligges> Thank you! > > # Colour the ellipses to emphasize the differences > corr.mtcars <- cor(mtcars) > ord <- order(corr.mtcars[1,]) > xc <- corr.mtcars[ord, ord] > plotcorr( xc, col=cm.colors(11)[5*xc + 6]) > > > With regards, Lep pozdrav > Gregor GORJANC > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Duncan Murdoch
2004-Oct-17 13:34 UTC
[R] Plotcorr: colour the ellipses to emphasize the differences
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