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