[Vegan-commits] r2210 - in branches/2.0: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jun 2 18:48:33 CEST 2012
Author: jarioksa
Date: 2012-06-02 18:48:32 +0200 (Sat, 02 Jun 2012)
New Revision: 2210
Modified:
branches/2.0/R/ordiplot3d.R
branches/2.0/inst/ChangeLog
branches/2.0/inst/NEWS.Rd
branches/2.0/man/ordiplot3d.Rd
Log:
merge: ordiplot3d returns envfit.convert() -- relevant fixes r2157 thru 2168, 2208
Modified: branches/2.0/R/ordiplot3d.R
===================================================================
--- branches/2.0/R/ordiplot3d.R 2012-06-02 10:47:59 UTC (rev 2209)
+++ branches/2.0/R/ordiplot3d.R 2012-06-02 16:48:32 UTC (rev 2210)
@@ -45,6 +45,37 @@
col = arr.col)
}
}
+ ## save the location of the origin
+ pl$origin <- matrix(unlist(pl$xyz.convert(0, 0, 0)), nrow=1)
+ ## Add function that flattens 3d envfit object so that it can be
+ ## projected on the created 3d graph
+ xyz2xy <- pl$xyz.convert
+ envfit.convert <- function(object) {
+ if (!is.null(object$vectors)) {
+ rn <- rownames(object$vectors$arrows)
+ arr <- object$vectors$arrows[, choices, drop = FALSE]
+ arr <- sapply(xyz2xy(arr), cbind)
+ if (!is.matrix(arr))
+ arr <- matrix(arr, ncol = 2)
+ arr <- sweep(arr, 2, pl$origin)
+ rownames(arr) <- rn
+ object$vectors$arrows <- arr
+ }
+ if (!is.null(object$factors)) {
+ rn <- rownames(object$factors$centroids)
+ object$factors$centroids <-
+ object$factors$centroids[ ,choices, drop = FALSE]
+ object$factors$centroids <-
+ sapply(xyz2xy(object$factors$centroids), cbind)
+ if (!is.matrix(object$factors$centroids))
+ object$factors$centroids <-
+ matrix(object$factors$centroids, ncol = 2)
+ rownames(object$factors$centroids) <- rn
+ }
+ object
+ }
+ pl$envfit.convert <- envfit.convert
+ ## save projected coordinates of points
tmp <- pl$xyz.convert(x)
pl$points <- cbind(tmp$x, tmp$y)
rownames(pl$points) <- rownames(x)
Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog 2012-06-02 10:47:59 UTC (rev 2209)
+++ branches/2.0/inst/ChangeLog 2012-06-02 16:48:32 UTC (rev 2210)
@@ -17,6 +17,8 @@
* merge r2170: bioenv accepts dissimilarities as input.
* merge r2167: warn about unequal aspect ratio in ordiplot3d.
* merge r2162: set equal axis scales for ordiplot3d.
+ * merge r2157:2160,2167,2168,2208: ordiplot3d returns
+ envfit.convert().
* merge r2156: betadisper example adapted for default spatial
median.
* merge r2150: monoMDS checks that the number of dissimilarities
Modified: branches/2.0/inst/NEWS.Rd
===================================================================
--- branches/2.0/inst/NEWS.Rd 2012-06-02 10:47:59 UTC (rev 2209)
+++ branches/2.0/inst/NEWS.Rd 2012-06-02 16:48:32 UTC (rev 2210)
@@ -60,6 +60,11 @@
\code{ordihull} puts labels (with argument \code{label = TRUE})
now in the real polygon centre.
+ \item \code{ordiplot3d} returns function \code{envfit.convert}
+ and the projected location of the \code{origin}. Together
+ these functions can be used to add \code{envfit} results to
+ existint \code{ordiplot3d} plots.
+
\item Function \code{ordipointlabel} gained argument to
\code{select} only some of the items for plotting. The
argument can be used only with one set of points.
Modified: branches/2.0/man/ordiplot3d.Rd
===================================================================
--- branches/2.0/man/ordiplot3d.Rd 2012-06-02 10:47:59 UTC (rev 2209)
+++ branches/2.0/man/ordiplot3d.Rd 2012-06-02 16:48:32 UTC (rev 2210)
@@ -129,16 +129,19 @@
Function \code{ordiplot3d} returns invisibly an object of class
\code{"ordiplot3d"} inheriting from \code{\link{ordiplot}}. The
return object will contain the coordinates projected onto two
- dimensions for \code{"points"}, and possibly for the heads of
- \code{"arrows"} and \code{"centroids"} of environmental
- variables. Functions like \code{\link{identify.ordiplot}},
+ dimensions for \code{points}, and the projected coordinates of
+ \code{origin}, and possibly the projected coordinates of the heads
+ of \code{arrows} and \code{centroids} of environmental variables.
+ Functions like \code{\link{identify.ordiplot}},
\code{\link{points.ordiplot}}, \code{\link{text.ordiplot}} can use
this result, as well as \code{\link{ordihull}} and other functions
- documented with the latter. In addition, the result will contain the
- object returned by \code{\link[scatterplot3d]{scatterplot3d}},
- including function \code{xyz.convert} which projects
- three-dimensional coordinates onto the plane used in the current
- plot (see Examples).
+ documented with the latter. The result will also contain the object
+ returned by \code{\link[scatterplot3d]{scatterplot3d}}, including
+ function \code{xyz.convert} which projects three-dimensional
+ coordinates onto the plane used in the current plot (see
+ Examples). In addition, there is a function \code{envfit.convert}
+ that projects a three-dimensional \code{\link{envfit}} object to the
+ current plot.
Function \code{ordirgl} returns nothing.
@@ -205,6 +208,17 @@
### Add species using xyz.convert function returned by ordiplot3d
sp <- scores(ord, choices=1:3, display="species", scaling=3)
text(pl$xyz.convert(sp), rownames(sp), cex=0.7, xpd=TRUE)
+### Two ways of adding fitted variables to ordination plots
+ord <- cca(dune)
+ef <- envfit(ord ~ Moisture + A1, dune.env, choices = 1:3)
+### 1. use argument 'envfit'
+ordiplot3d(ord, envfit = ef)
+### 2. use returned envfit.convert function for better user control
+pl3 <- ordiplot3d(ord)
+plot(pl3$envfit.convert(ef), at = pl3$origin)
+### envfit.convert() also handles different 'choices' of axes
+pl3 <- ordiplot3d(ord, choices = c(1,3,2))
+plot(pl3$envfit.convert(ef), at = pl3$origin)
### ordirgl
ordirgl(ord, size=2)
ordirgl(ord, display = "species", type = "t")
More information about the Vegan-commits
mailing list