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

Martin Maechler maechler at stat.math.ethz.ch
Sat Jan 29 22:47:24 CET 2011


>>>>> Tobias Verbeke <tobias.verbeke at openanalytics.eu>
>>>>>     on Tue, 25 Jan 2011 21:27:41 +0100 writes:

    > 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.

Thank you, Tobias.

Note BTW, that on Linux I don't have your problems that the
label is "not drawn" when it does not fit.
For me, it just is clipped (to the figure region as you note),
so "chopped off" but the part inside the figure box is well
visible.

I was searching a bit and did not find mentioned on ?par or
?clip that clipping happens device dependently,
but I vaguely recall to have seen it stated..

However the patch is a good idea, anyway,
and it will be in R 2.13.x..

Thanks again,
Martin Maechler

    > 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
    >> 
    >> 

    > ______________________________________________
    > R-devel at r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list