[Rd] patch dendrogram.R from stats [was: Re: dendrogram plot does not draw long labels ?]

Tobias Verbeke tobias.verbeke at openanalytics.eu
Tue Jan 25 21:27:41 CET 2011


L.S.

Please find below a patch for dendrogram.R (stats package)
against revision r54107 which allows one to pass the xpd
parameter as a component of the nodePar list (to be
passed to plot.dendrogram).

I hope I did not overlook anything.

Best,
Tobias

378a379
 >     lab.xpd <- Xtract("xpd", nPar, default = c(TRUE, TRUE), i)
391c392
< 	    text(X, Y, nodeText, xpd = TRUE, srt = srt, adj = adj,
---
 > 	    text(X, Y, nodeText, xpd = lab.xpd, srt = srt, adj = adj,
436c437
< 		text(xBot, yBot + vln, nodeText, xpd = TRUE,
---
 > 		text(xBot, yBot + vln, nodeText, xpd = lab.xpd,



On 01/25/2011 04:34 PM, Karl Forner wrote:
> Hi Tobias and thank you for your reply,
>
> Using your insight I managed to work-around the issue (with some help)
> by increasing
> the "mai" option of par().
> For example a "mai" with first coordinate (bottom) set to 5 allows to
> display ~ 42 letters.
>
> We tried to change the xpd value in the text() call that you mentioned,
> but it did not seem to fix the problem.
>
> But I think this is very annoying: the dendrogram plot is meant to be
> the common unique plotting for all clustering stuff
> and suddenly if your labels are just too long, nothing get displayed,
> without even a warning.
> I suppose that the margins should be dynamically set based on the max
> label text drawn length...
>
> The hclust plot seemed to handle very nicely these long labels, but I
> need to display colored labels and the only way I found is to use the
> plot.dendrogram for this.
>
> Best,
>
> Karl
>
> On Tue, Jan 25, 2011 at 12:17 PM, Tobias Verbeke
> <tobias.verbeke at openanalytics.eu
> <mailto:tobias.verbeke at openanalytics.eu>> wrote:
>
>     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
>
>



More information about the R-devel mailing list