[Vegan-commits] r2435 - pkg/vegan/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Feb 13 17:52:34 CET 2013
Author: jarioksa
Date: 2013-02-13 17:52:34 +0100 (Wed, 13 Feb 2013)
New Revision: 2435
Modified:
pkg/vegan/R/tabasco.R
Log:
tabasco did not return (invisibly) correct indices when dendrograms were used
Modified: pkg/vegan/R/tabasco.R
===================================================================
--- pkg/vegan/R/tabasco.R 2013-02-13 14:24:23 UTC (rev 2434)
+++ pkg/vegan/R/tabasco.R 2013-02-13 16:52:34 UTC (rev 2435)
@@ -19,20 +19,19 @@
else if (inherits(use, "hclust")) {
if (!is.null(site.ind))
stop("'hclust' tree cannot be 'use'd with 'site.ind'")
- site.ind <- seq_len(nrow(x))
+ site.ind <- use$order
if (is.null(sp.ind))
- sp.ind <- order(wascores(order(use$order), x))
+ sp.ind <- order(wascores(order(site.ind), x))
Colv <- as.dendrogram(use)
}
else if (inherits(use, "dendrogram")) {
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)]
+ names(site.ind) <- rownames(x)
+ site.ind <- site.ind[labels(use)]
if (is.null(sp.ind))
- sp.ind <- order(wascores(order(o), x))
+ sp.ind <- order(wascores(order(site.ind), x))
Colv <- use
}
else if (is.list(use)) {
@@ -59,6 +58,8 @@
sp.ind <- as.dendrogram(sp.ind)
Rowv <- sp.ind
sp.ind <- seq_len(ncol(x))
+ names(sp.ind) <- colnames(x)
+ sp.ind <- sp.ind[labels(Rowv)]
}
if (!is.null(sp.ind) && is.logical(sp.ind))
sp.ind <- (1:ncol(x))[sp.ind]
@@ -69,7 +70,7 @@
if (is.null(site.ind))
site.ind <- 1:nrow(x)
if (!missing(select)) {
- if (inherits(use, c("hclust", "dendrogram")))
+ if (!is.na(Colv))
stop("sites cannot be 'select'ed with dendrograms or hclust trees")
if (!is.logical(select))
select <- sort(site.ind) %in% select
@@ -81,9 +82,19 @@
stake <- colSums(x[site.ind, ]) > 0
}
sp.ind <- sp.ind[stake[sp.ind]]
- x <- x[site.ind, sp.ind]
- x <- as.matrix(x)
- x <- t(x)
+ ## heatmap will reorder items by dendrogram so that we need to
+ ## give indices in the unsorted order if rows or columns have a
+ ## dendrogram
+ if (is.na(Colv[1]))
+ rind <- site.ind
+ else
+ rind <- sort(site.ind)
+ if (is.na(Rowv[1]))
+ cind <- sp.ind
+ else
+ cind <- sort(sp.ind)
+ ## we assume t() changes data.frame to a matrix
+ x <- t(x[rind, cind])
sp.nam <- rownames(x)
sp.len <- max(nchar(sp.nam))
heatmap((max(x) - x), Rowv, Colv, scale = "none", ...)
More information about the Vegan-commits
mailing list