[Rd] plot.hclust: dendrogram too large for window (PR#4197)

kleiweg at let.rug.nl kleiweg at let.rug.nl
Wed Sep 17 02:30:58 MEST 2003


plot.hclust:
Setting up a window for a dendrogram assumes the first link is
the shortest and the last is the longest. This is not always the
case when the clustering was done with hclust, method="median"
or method="centroid", and the dendrogram sometimes doesn't fit
within the window.

I propose the fix listed below.


src/main/

--- plot.c     Wed Sep 17 01:03:39 2003
+++ plot.c.new      Wed Sep 17 01:21:59 2003
@@ -3314,7 +3314,7 @@
 SEXP do_dendwindow(SEXP call, SEXP op, SEXP args, SEXP env)
 {
     int i, imax, n;
-    double pin, *ll, tmp, yval, *y, ymin, ymax, yrange;
+    double pin, *ll, tmp, yval, *y, ymin, ymax, yrange, m;
     SEXP originalArgs, merge, height, llabels, str;
     char *vmax;
     DevDesc *dd;
@@ -3357,8 +3357,14 @@
     ll =  (double*)R_alloc(n, sizeof(double));
     dnd_lptr = &(INTEGER(merge)[0]);
     dnd_rptr = &(INTEGER(merge)[n]);
-    ymin = REAL(height)[0];
-    ymax = REAL(height)[n - 1];
+    ymax = ymin = REAL(height)[0];
+    for (i = 1; i < n; i++) {
+      m = REAL(height)[i];
+      if (m > ymax)
+       ymax = m;
+      if (m < ymin)
+       ymin = m;
+    }
     pin = Rf_gpptr(dd)->pin[1];
     for (i = 0; i < n; i++) {
        str = STRING_ELT(llabels, i);




--please do not edit the information below--

Version:
 platform = i686-pc-linux-gnu
 arch = i686
 os = linux-gnu
 system = i686, linux-gnu
 status =
 major = 1
 minor = 7.1
 year = 2003
 month = 06
 day = 16
 language = R

Search Path:
 .GlobalEnv, package:methods, package:ctest, package:mva, package:modreg, package:nls, package:ts, Autoloads, package:base



More information about the R-devel mailing list