[R] Forcing ticks in plot for hclust object outside the limits

Uwe Ligges
2005-05-28T17:58:18Z

Ale? ?iberna wrote:
> Hello!
>
> I have the following problem.
>
> I would like to plot the hclust object "hcd" (bellow, at the end
of the
> mail) with ticks at seq(0.05,0.25,by=0.05). I tried using the code
> plot(hcd)
> and
> plot(hcd,axes=FALSE)
> axis(2,seq(0.05,0.25,by=0.05))
>
> In both cases, the resoult is the same, ticks at 0.05 and 0.25 are not
> printed. I tried changing the ylim argumet in plot, however I got a
> warning "parameter "ylim" couldn't be set in high-level
plot() function".
>
> I would like to force those two ticks. Can this be done with axis or
> plot, or should I use "lines"?


Not easy with the plot method for a hclust object, because 0.05 and 0.25
are getting clipped, because they are out od the "usr" coordinated of
the plot.

Of course you could hack plot.hclust (in Namespace stats) by modifying
.../R/library/src/stats/R/hclust.R as follows (in order to provide a
proper ylim argument):

diff hclust.R-orig hclust.R

91c91,92
<               sub = NULL, xlab = NULL, ylab = "Height", ...)
---
 >               sub = NULL, xlab = NULL, ylab = "Height",
 >               ylim = NULL, ...)
116c117,120
<     .Internal(dend.window(n, merge, height, hang, labels, ...))
---
 >     height2 <- height
 >     if(!is.null(ylim))
 >         height2 <- c(range(ylim), rep(ylim[1], length(height) - 2))
 >     .Internal(dend.window(n, merge, height2, hang, labels, ...))


Note that this quick hack is a *dirty* solution.

Uwe Ligges




> Thanks in advance for any suggestions!
> Ale? ?iberna
>
>
> "hcd" <-
> structure(list(merge = structure(as.integer(c(-4, -5, -1, -7,
> -6, -10, -3, -12, -8, -2, 8, 1, -9, -11, 2, 3, -13, 4, 6, 5,
> 7, 9, 10, 11)), .Dim = as.integer(c(12, 2))), height =
> c(0.0906288626438465,
> 0.10278145998519, 0.114885217561497, 0.127812745765521, 0.132377986666522,
> 0.168594637784091, 0.177187802444346, 0.209803430657638, 0.210361529934791,
> 0.218946973173863, 0.234000873708654, 0.235702383243089), order =
> as.integer(c(4,
> 9, 12, 6, 13, 2, 8, 3, 10, 7, 1, 5, 11)), labels = NULL, method =
"single",
>    call = quote(hclust(d = d, method = "single")), dist.method =
NULL),
> .Names = c("merge",
> "height", "order", "labels",
"method", "call", "dist.method"), class =
> "hclust")
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html