[R] Colored Dendrogram

Richard C. Yeh richard.c.yeh at gmail.com
Thu Dec 28 07:43:13 CET 2006


In your colLab function, you are assigning the label colors using the  
mycols 4-element vector, which you generated using the rainbow()  
function.  So, to pick colors using the values in vector c, normalize c  
and then try the colorRamp function.

I don't know how to use that function, myself, so instead I did:

# Generate lots of colors, starting at blue (0.6) and ending at red (0)
# We started at blue because you wanted blue for the lower-valued elements
# and red for the higher-valued elements.
pal <- rainbow(4000,start=0.5,end=0.05)
# Normalize vector c to the range 0-1 (well, not really)
# and scale the range to a color index
mycols <- pal[length(pal)*c/max(c)]

Then define your colLab function and run.


On Tue, 26 Dec 2006 11:20:45 -0500, Om <ompandey at gmail.com> wrote:
> In this dendrogram, each leaf is colored differently. But, I do not want  
> the
> leaf colored on a random basis. I want to assign color for leaf on basis  
> of
> some criterion.
>
> My actual problem: How to generate a dendrogram with the leaf colored
> according to the values in the second matrix (which is 4x1 dim, say  
> matrix
> c)? Meaning, the leaf 1 and 2 should be colored in neighboring spectra of
> color (say different shade of red) and leaf 3 and 4 in a different color
> (say different shade of blue)
>
> Below is R code and data matrix



More information about the R-help mailing list