[Vegan-commits] r2854 - in pkg/vegan: . R inst
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Feb 9 08:41:48 CET 2014
Author: jarioksa
Date: 2014-02-09 08:41:46 +0100 (Sun, 09 Feb 2014)
New Revision: 2854
Added:
pkg/vegan/R/scores.hclust.Rd
Modified:
pkg/vegan/NAMESPACE
pkg/vegan/R/as.hclust.spantree.R
pkg/vegan/inst/ChangeLog
Log:
add scores.hclust (to be removed later)
Modified: pkg/vegan/NAMESPACE
===================================================================
--- pkg/vegan/NAMESPACE 2014-02-08 07:31:55 UTC (rev 2853)
+++ pkg/vegan/NAMESPACE 2014-02-09 07:41:46 UTC (rev 2854)
@@ -389,6 +389,7 @@
S3method(scores, decorana)
S3method(scores, default)
S3method(scores, envfit)
+S3method(scores, hclust)
S3method(scores, lda)
S3method(scores, metaMDS)
S3method(scores, monoMDS)
Modified: pkg/vegan/R/as.hclust.spantree.R
===================================================================
--- pkg/vegan/R/as.hclust.spantree.R 2014-02-08 07:31:55 UTC (rev 2853)
+++ pkg/vegan/R/as.hclust.spantree.R 2014-02-09 07:41:46 UTC (rev 2854)
@@ -126,3 +126,33 @@
x$order <- rev(x$order)
x
}
+
+### Get coordinates for internal or terminal nodes (leaves) that would
+### be used in plot.hclust
+
+`scores.hclust` <-
+ function(x, display = "internal", ...)
+{
+ extnam <- c("leaves", "terminal")
+ intnam <- c("internal")
+ display <- match.arg(display, c(extnam, intnam))
+ ## Terminal nodes (leaves): plot.hclust scales x-axis for n points
+ ## as 1..n. The y-value is the 'height' where the terminal node
+ ## was fused to the tree.
+ if(display %in% extnam) {
+ merge <- x$merge
+ y <- numeric(nrow(merge) + 1)
+ for(i in 1:nrow(merge))
+ for(j in 1:2)
+ if(merge[i,j] < 0)
+ y[-merge[i,j]] <- x$height[i]
+ xx <- order(x$order)
+ xy <- cbind(`x` = xx, `height` = y)
+ } else {
+ ## Internal nodes are given in the order they were fused which
+ ## also is the order of 'height'
+ xx <- reorder(x, order(x$order), agglo.FUN = "uwmean")$value
+ xy <- cbind(`x`= xx, `height` = x$height)
+ }
+ xy
+}
Added: pkg/vegan/R/scores.hclust.Rd
===================================================================
--- pkg/vegan/R/scores.hclust.Rd (rev 0)
+++ pkg/vegan/R/scores.hclust.Rd 2014-02-09 07:41:46 UTC (rev 2854)
@@ -0,0 +1,70 @@
+\name{scores.hclust}
+\alias{scores.hclust}
+
+\title{
+ Coordinates of Leaves and Internal Nodes in a hclust Tree
+}
+
+\description{ The function finds the coordinates that will be used for
+ internal nodes and leaves when an \code{\link{hclust}} object is
+ plotted. These help in annotating the plotted dendrogram. }
+
+\usage{
+scores.hclust(x, display = "internal", ...)
+}
+
+\arguments{
+ \item{x}{
+ An \code{\link{hclust}} result object.
+}
+ \item{display}{
+ Return \code{"internal"} nodes or \code{"terminal"} nodes (also
+ called \code{"leaves"}.
+}
+ \item{\dots}{
+ Other arguments passed to the function (ignored).
+}
+}
+
+\details{
+
+ The function returns the coordinates of nodes in an
+ \code{\link{hclust}} plot as two-column matrix. First column called
+ \code{x} gives the horizontal coordinates which for \eqn{n} terminal
+ nodes (leaves) is an integer sequence \eqn{1..n}. The second column
+ called \code{height} gives the merge value. For terminal nodes
+ (leaves) this the value at which the item is merged to the tree, and
+ in plots the labels can still hang below this level, as defined by
+ the argument \code{hang} in \code{\link{plot.hclust}}.
+
+ The function only works with \code{\link{hclust}} objects; it does
+ not work with \code{\link{dendrogram}}.
+
+}
+
+\value{
+ A two-column matrix of coordinates.
+}
+
+\author{
+ Jari Oksanen.
+}
+
+\note{
+ This function may be removed as useless.
+}
+
+
+\seealso{
+ \code{\link{hclust}}, \code{\link{plot.hclust}}.
+}
+\examples{
+## Show values that were used in reordering a tree
+data(mite, mite.env)
+hc <- hclust(vegdist(mite))
+hc <- with(mite.env, reorder(hc, WatrCont))
+with(mite.env, plot(hc, labels=round(WatrCont), cex=0.7))
+ordilabel(scores(hc), label=round(hc$value), cex=0.7)
+}
+\keyword{ multivariate }
+
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2014-02-08 07:31:55 UTC (rev 2853)
+++ pkg/vegan/inst/ChangeLog 2014-02-09 07:41:46 UTC (rev 2854)
@@ -12,7 +12,7 @@
and now removed.
* as.hclust.spantree: a new function to cast a "spantree" result
- object to an "hclust" tree.
+ object to an "hclust" tree.
* hclust: add reorder() and rev() methods for standard "hclust"
trees of R. I have no clue why base R does not have these
@@ -23,6 +23,11 @@
here will use group sizes as weights and the value of the group
will be the mean of its leaves (terminal nodes).
+ Add scores() method to extract coordinates of internal nodes or
+ leaves from a plotted hclust() tree. The function is whimsical and
+ may be removed before release (it is documented separately to make
+ this easier).
+
* biplot.rda: failed in axis scaling with negative 'scaling'
values when some species had zero variance (and hence species
scores was 0/0 = NaN).
More information about the Vegan-commits
mailing list