From tobias.verbeke at openanalytics.eu  Tue Jan 25 12:17:27 2011
From: tobias.verbeke at openanalytics.eu (Tobias Verbeke)
Date: Tue, 25 Jan 2011 12:17:27 +0100
Subject: [Rd] dendrogram plot does not draw long labels ?
In-Reply-To: <AANLkTikuvd7q4xbyzEdfp+G_k1CsEM_db7zxZXpiQcWg@mail.gmail.com>
References: <AANLkTikuvd7q4xbyzEdfp+G_k1CsEM_db7zxZXpiQcWg@mail.gmail.com>
Message-ID: <4D3EB147.8000906@openanalytics.eu>

Hi Karl,

On 01/25/2011 11:27 AM, Karl Forner wrote:

> It seems that the plot function for dendrograms does not draw labels when
> they are too long.
>
>> hc<- hclust(dist(USArrests), "ave")
>> dend1<- as.dendrogram(hc)
>> dend2<- cut(dend1, h=70)
>> dd<- dend2$lower[[1]]
>> plot(dd) # first label is drawn
>> attr(dd[[1]], "label")<- "aaaaaaaaaaaaaaaaaa"
>> plot(dd) # first label is NOT drawn
>
> Is this expected ?

Reading the code of stats:::plotNode, yes.

Clipping to the figure region is hard-coded.

You can see it is clipping to the figure region as follows:

hc <- hclust(dist(USArrests), "ave")
dend1 <- as.dendrogram(hc)
dend2 <- cut(dend1, h=70)
dd <- dend2$lower[[1]]
op <- par(oma = c(8,4,4,2)+0.1, xpd = NA)
plot(dd) # first label is drawn
attr(dd[[1]], "label") <- "abcdefghijklmnopqrstuvwxyz"
plot(dd) # first label is NOT drawn
box(which = "figure")
par(op)

> Is it possible to force the drawing ?

These are (from very quick reading -- not verified)
the culprit lines in plotNode, I think:

text(xBot, yBot + vln, nodeText, xpd = TRUE, # <- clipping hard-coded
                   cex = lab.cex, col = lab.col, font = lab.font)

Best,
Tobias



[Rd] dendrogram plot does not draw long labels ?
Tobias Verbeke