[Vegan-commits] r2433 - in pkg/vegan: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 12 15:00:37 CET 2013


Author: jarioksa
Date: 2013-02-12 15:00:37 +0100 (Tue, 12 Feb 2013)
New Revision: 2433

Modified:
   pkg/vegan/R/tabasco.R
   pkg/vegan/man/vegemite.Rd
Log:
tabasco did not correctly order sites when 'use' was a dendrogram
because heatmap rearranged the once arranged data.

site.ind/sp.ind take a preference over 'use' also in tabasco (like
documented for vegemite) or given an error.

'select' or 'site.ind' given an error when 'use' is dendrogram/tree.

Rd page updated for tabasco.


Modified: pkg/vegan/R/tabasco.R
===================================================================
--- pkg/vegan/R/tabasco.R	2013-02-12 12:45:52 UTC (rev 2432)
+++ pkg/vegan/R/tabasco.R	2013-02-12 14:00:37 UTC (rev 2433)
@@ -17,20 +17,22 @@
                 sp.ind <- order(wascores(use, x))
         }
         else if (inherits(use, "hclust")) {
-            if (is.null(site.ind)) 
-                site.ind <- use$order
+            if (!is.null(site.ind))
+                stop("'hclust' tree cannot be 'use'd with 'site.ind'")
+            site.ind <- seq_len(nrow(x))
             if (is.null(sp.ind)) 
-                sp.ind <- order(wascores(order(site.ind), x))
+                sp.ind <- order(wascores(order(use$order), x))
             Colv <- as.dendrogram(use)
         }
         else if (inherits(use, "dendrogram")) {
-            if (is.null(site.ind)) {
-                site.ind <- 1:nrow(x)
-                names(site.ind) <- rownames(x)
-                site.ind <- site.ind[labels(use)]
-            }
+            if (!is.null(site.ind))
+                stop("'dendrogram' cannot be 'use'd with 'site.ind'")
+            site.ind <- seq_len(nrow(x))
+            o <- seq_len(nrow(x))
+            names(o) <- rownames(x)
+            o <- o[labels(use)]
             if (is.null(sp.ind)) 
-                sp.ind <- order(wascores(order(site.ind), x))
+                sp.ind <- order(wascores(order(o), x))
             Colv <- use
         }
         else if (is.list(use)) {
@@ -51,6 +53,13 @@
                 sp.ind <- order(wascores(tmp, x))
         }
     }
+    ## see if sp.ind is a dendrogram or hclust tree
+    if (inherits(sp.ind, c("hclust", "dendrogram"))) {
+        if (!inherits(sp.ind, "dendrogram"))
+            sp.ind <- as.dendrogram(sp.ind)
+        Rowv <- sp.ind
+        sp.ind <- seq_len(ncol(x))
+    }
     if (!is.null(sp.ind) && is.logical(sp.ind))
         sp.ind <- (1:ncol(x))[sp.ind]
     if (!is.null(site.ind) && is.logical(site.ind))
@@ -60,6 +69,8 @@
     if (is.null(site.ind)) 
         site.ind <- 1:nrow(x)
     if (!missing(select)) {
+        if (inherits(use, c("hclust", "dendrogram")))
+            stop("sites cannot be 'select'ed with dendrograms or hclust trees")
         if (!is.logical(select))
             select <- sort(site.ind) %in% select
         stake <- colSums(x[select, , drop = FALSE]) > 0

Modified: pkg/vegan/man/vegemite.Rd
===================================================================
--- pkg/vegan/man/vegemite.Rd	2013-02-12 12:45:52 UTC (rev 2432)
+++ pkg/vegan/man/vegemite.Rd	2013-02-12 14:00:37 UTC (rev 2433)
@@ -25,7 +25,8 @@
   \item{use}{Either a vector, or an object from \code{cca},
     \code{decorana} \emph{etc.} or \code{hclust} or a
     \code{\link{dendrogram}} for ordering sites and species.} 
-  \item{sp.ind}{Species indices. }
+  \item{sp.ind}{Species indices. In \code{tabasco}, this can also be an
+    \code{\link{hclust}} tree or a \code{\link{dendrogram}}. }
   \item{site.ind}{Site indices. }
   \item{zero}{Character used for zeros. }
   \item{select}{Select a subset of sites.  This can be a logical vector
@@ -55,9 +56,10 @@
   \code{\link{hclust}}, a \code{\link{dendrogram}} or any ordination
   result recognized by \code{\link{scores}} (all ordination methods in
   \pkg{vegan} and some of those not in \pkg{vegan}). The
-  \code{\link{hclust}} an \code{\link{dendrogram}} must be for
-  sites. The dendrogram is displayed in above the sites in
-  \code{tabasco}.
+  \code{\link{hclust}} and \code{\link{dendrogram}} must be for
+  sites. The dendrogram is displayed above the sites in
+  \code{tabasco}.  No dendrogram for species is displayed, except when
+  given in \code{sp.ind}.
 
   If \code{use} is a vector, it is used
   for ordering sites.  If \code{use} is an object from ordination, both
@@ -73,13 +75,19 @@
   clustering, but in some cases species are still nicely ordered (please
   note that you can \code{\link{reorder.dendrogram}} to have such a
   natural order).
-  Alternatively, species and sites can be ordered explicitly giving
-  their indices or names in parameters \code{sp.ind} and
-  \code{site.ind}.  If these are given, they take precedence over
-  \code{use}. A subset of sites can be displayed using argument
-  \code{select}, but this cannot be used to order sites, but you still
-  must give \code{use} or \code{site.ind}.
 
+  Species and sites can be ordered explicitly giving their indices or
+  names in parameters \code{sp.ind} and \code{site.ind}.  If these are
+  given, they take precedence over \code{use}. A subset of sites can be
+  displayed using argument \code{select}, but this cannot be used to
+  order sites, but you still must give \code{use} or \code{site.ind}.
+  However, \code{tabasco} makes two exceptions: \code{site.ind} and
+  \code{select} cannot be used when \code{use} is an
+  \code{\link{hclust}} tree or a \code{\link{dendrogram}}. In addition,
+  the \code{sp.ind} can also be an \code{\link{hclust}} tree or a
+  \code{\link{dendrogram}}, and in that case the dendrogram is plotted
+  on the left side of the \code{\link{heatmap}}.
+
   If \code{scale} is given, \code{vegemite} calls
   \code{coverscale} to transform percent cover
   scale or some other scales into traditional class scales used in
@@ -102,13 +110,13 @@
   10 with \code{X} and positive values below 1 with \code{+}. 
 }
 \value{
-  The function is used mainly to print a table, but it returns
+  The functions are used mainly to display a table, but it returns
   (invisibly) a list
   with items:
   \item{species}{Ordered species indices}
   \item{sites}{Ordered site indices}
   These items can be used as arguments \code{sp.ind} and \code{site.ind}
-  to reproduce the table. In addition to the proper table, the function
+  to reproduce the table. In addition to the proper table, \code{vegemite}
   prints the numbers of species and sites and the name of the used cover
   scale at the end.
 }



More information about the Vegan-commits mailing list