[Vegan-commits] r932 - in pkg/vegan: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 20 18:48:41 CEST 2009
Author: jarioksa
Date: 2009-08-20 18:48:34 +0200 (Thu, 20 Aug 2009)
New Revision: 932
Added:
pkg/vegan/R/summary.ordiellipse.R
pkg/vegan/R/summary.ordihull.R
Modified:
pkg/vegan/R/ordiellipse.R
pkg/vegan/inst/ChangeLog
pkg/vegan/man/ordihull.Rd
Log:
ordihull & ordiellipse got summary method that returns centres and areas
Modified: pkg/vegan/R/ordiellipse.R
===================================================================
--- pkg/vegan/R/ordiellipse.R 2009-08-20 14:04:21 UTC (rev 931)
+++ pkg/vegan/R/ordiellipse.R 2009-08-20 16:48:34 UTC (rev 932)
@@ -43,6 +43,7 @@
if (label)
ordiArgAbsorber(mat$center[1], mat$center[2], labels=is,
FUN = text, ...)
+ mat$scale <- t
res[[is]] <- mat
}
}
Added: pkg/vegan/R/summary.ordiellipse.R
===================================================================
--- pkg/vegan/R/summary.ordiellipse.R (rev 0)
+++ pkg/vegan/R/summary.ordiellipse.R 2009-08-20 16:48:34 UTC (rev 932)
@@ -0,0 +1,12 @@
+### Centres and areas of plotted ellipses. The principal axes of the
+### conic (oblique ellipse) are found from the eigenvalues of the
+### covariance matrix.
+`summary.ordiellipse` <-
+ function(object, ...)
+{
+ cnts <- sapply(object, function(x) x$center)
+ areas <- sapply(object,
+ function(x)
+ prod(sqrt(eigen(x$cov)$values)) * pi * x$scale^2)
+ rbind(cnts, `Area` = areas)
+}
Added: pkg/vegan/R/summary.ordihull.R
===================================================================
--- pkg/vegan/R/summary.ordihull.R (rev 0)
+++ pkg/vegan/R/summary.ordihull.R 2009-08-20 16:48:34 UTC (rev 932)
@@ -0,0 +1,29 @@
+### Centres and areas of convex hulls. The area of the *convex* polygon
+### is found as the *sum* of the areas of triangles.
+`summary.ordihull` <-
+ function(object, ...)
+{
+ ## The area of triangle from vertices using eq. 8.10 of Spiegel,
+ ## Liu & Lipschitz (1999), Mathematical Handbook of Formulas and
+ ## Tables (2nd ed.), McGraw & Hill. The hull is closed, so that
+ ## first and last point are identical.
+ triarea <- function(x) {
+ ones <- rep(1, 3)
+ if (nrow(x) < 4)
+ return(0)
+ if (nrow(x) == 4)
+ return(abs(det(cbind(x[-1,], ones))/2))
+ else {
+ sol <- 0
+ cnt <- colMeans(x[-1,])
+ for (i in 2:nrow(x)) {
+ mat <- cbind(rbind(cnt, x[(i-1):i,]), ones)
+ sol <- sol + abs(det(mat)/2)
+ }
+ return(sol)
+ }
+ }
+ areas <- sapply(object, function(x) triarea(x))
+ cnts <- sapply(object, function(x) colMeans(x[-1,]))
+ rbind(cnts, `Area` = areas)
+}
Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog 2009-08-20 14:04:21 UTC (rev 931)
+++ pkg/vegan/inst/ChangeLog 2009-08-20 16:48:34 UTC (rev 932)
@@ -8,10 +8,9 @@
name of the group in the centre of the ellipse or the hull. The
functions now return invisibly data on their plots for each
plotted item: ordiellipse() the covariance matrix (cov.wt()
- result), and ordihull() the coordinates of the hull
- vertices. Nothing is done with these yet, but the intention is to
- write a summary() method to give the coordinates of the centres
- and surface areas of the plotted hulls or ellipses.
+ result), and ordihull() the coordinates of the hull vertices.
+ These inivisible results have a summary() method that displays the
+ centres of the hulls or ellipses and their surface areas.
* ordiellipse: does not depend on the 'ellipse' package, but finds
the coordinates of ellipse using the equation taken from the 'car'
Modified: pkg/vegan/man/ordihull.Rd
===================================================================
--- pkg/vegan/man/ordihull.Rd 2009-08-20 14:04:21 UTC (rev 931)
+++ pkg/vegan/man/ordihull.Rd 2009-08-20 16:48:34 UTC (rev 932)
@@ -9,6 +9,8 @@
\alias{weights.cca}
\alias{weights.rda}
\alias{weights.decorana}
+\alias{summary.ordihull}
+\alias{summary.ordiellipse}
\title{Add Graphical Items to Ordination Diagrams}
\description{
@@ -97,6 +99,14 @@
An ellipsoid hull can be drawn with function
\code{\link[cluster]{ellipsoidhull}} of package \pkg{cluster}.
+ Functions \code{ordihull} and \code{ordiellipse} return the
+ \code{\link{invisible}} plotting structure. In \code{ordihull} this
+ is a list of coordinates of the hull and in \code{ordiellipse} a
+ list of covariance matrices and scales used in drawing the
+ ellipses. These result objects have a summary method that returns
+ the coordinates of the centroids of the ellipses or hulls and their
+ surface areas in user units.
+
Function \code{ordiarrows} draws
\code{\link{arrows}} and \code{ordisegments} draws line
\code{\link{segments}} between successive items in the
@@ -143,13 +153,17 @@
attach(dune.env)
## pass non-graphical arguments without warnings
plot(mod, type="n", scaling = 3)
-ordihull(mod, Management, scaling = 3, label = TRUE)
+## Catch the invisible result of ordihull...
+pl <- ordihull(mod, Management, scaling = 3, label = TRUE)
+## ... and find centres and areas of the hulls
+summary(pl)
ordispider(mod, col="red", scaling = 3)
plot(mod, type = "p", display="sites")
ordicluster(mod, hclust(vegdist(dune)), prune=3, col = "blue")
plot(mod, type="n", display = "sites")
text(mod, display="sites", labels = as.character(Management))
-ordiellipse(mod, Management, kind="se", conf=0.95, lwd=2, col="blue")
+pl <- ordiellipse(mod, Management, kind="se", conf=0.95, lwd=2, col="blue")
+summary(pl)
}
\keyword{aplot }
More information about the Vegan-commits
mailing list