[Vegan-commits] r957 - in branches/1.15: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 26 17:58:07 CEST 2009
Author: jarioksa
Date: 2009-08-26 17:58:07 +0200 (Wed, 26 Aug 2009)
New Revision: 957
Added:
branches/1.15/R/summary.ordiellipse.R
branches/1.15/R/summary.ordihull.R
Modified:
branches/1.15/R/ordiellipse.R
branches/1.15/R/ordihull.R
branches/1.15/inst/ChangeLog
branches/1.15/man/ordihull.Rd
Log:
merged summary for ordihull & ordiellipse into branches/115
Modified: branches/1.15/R/ordiellipse.R
===================================================================
--- branches/1.15/R/ordiellipse.R 2009-08-26 15:34:44 UTC (rev 956)
+++ branches/1.15/R/ordiellipse.R 2009-08-26 15:58:07 UTC (rev 957)
@@ -1,6 +1,7 @@
"ordiellipse" <-
function (ord, groups, display = "sites", kind = c("sd", "se"),
- conf, draw = c("lines", "polygon"), w = weights(ord, display),
+ conf, draw = c("lines", "polygon", "none"),
+ w = weights(ord, display),
show.groups, label = FALSE, ...)
{
## Define Circle for an ellipse: taken from the 'car' package
@@ -38,11 +39,12 @@
xy <- t(mat$center + t * t(Circle %*% chol(mat$cov)))
if (draw == "lines")
ordiArgAbsorber(xy, FUN = lines, ...)
- else
+ else if (draw == "polygon")
ordiArgAbsorber(xy[, 1], xy[, 2], FUN = polygon, ...)
- if (label)
+ if (label && draw != "none")
ordiArgAbsorber(mat$center[1], mat$center[2], labels=is,
FUN = text, ...)
+ mat$scale <- t
res[[is]] <- mat
}
}
Modified: branches/1.15/R/ordihull.R
===================================================================
--- branches/1.15/R/ordihull.R 2009-08-26 15:34:44 UTC (rev 956)
+++ branches/1.15/R/ordihull.R 2009-08-26 15:58:07 UTC (rev 957)
@@ -1,5 +1,6 @@
"ordihull" <-
- function (ord, groups, display = "sites", draw = c("lines", "polygon"),
+ function (ord, groups, display = "sites",
+ draw = c("lines", "polygon", "none"),
show.groups, label = FALSE, ...)
{
draw <- match.arg(draw)
@@ -20,9 +21,10 @@
hpts <- c(hpts, hpts[1])
if (draw == "lines")
ordiArgAbsorber(X[hpts, ], FUN = lines, ...)
- else ordiArgAbsorber(X[hpts,], FUN = polygon, ...)
- if (label) {
- cntr <- colMeans(X[hpts[-1],])
+ else if (draw == "polygon")
+ ordiArgAbsorber(X[hpts,], FUN = polygon, ...)
+ if (label && draw != "none") {
+ cntr <- colMeans(X)
ordiArgAbsorber(cntr[1], cntr[2], labels = is,
FUN = text, ...)
}
Copied: branches/1.15/R/summary.ordiellipse.R (from rev 956, pkg/vegan/R/summary.ordiellipse.R)
===================================================================
--- branches/1.15/R/summary.ordiellipse.R (rev 0)
+++ branches/1.15/R/summary.ordiellipse.R 2009-08-26 15:58:07 UTC (rev 957)
@@ -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)
+}
Copied: branches/1.15/R/summary.ordihull.R (from rev 956, pkg/vegan/R/summary.ordihull.R)
===================================================================
--- branches/1.15/R/summary.ordihull.R (rev 0)
+++ branches/1.15/R/summary.ordihull.R 2009-08-26 15:58:07 UTC (rev 957)
@@ -0,0 +1,25 @@
+### Centres and areas of convex hulls (simple polygons).
+`summary.ordihull` <-
+ function(object, ...)
+{
+ polyarea <- function(x) {
+ n <- nrow(x)
+ if (n < 4)
+ return(0)
+ else
+ abs(sum(x[-n,1]*x[-1,2] - x[-1,1]*x[-n,2]))/2
+ }
+ polycentre <- function(x) {
+ n <- nrow(x)
+ if (n < 4)
+ return(colMeans(x[-n,]))
+ xy <- x[-n,1]*x[-1,2] - x[-1,1]*x[-n,2]
+ A <- sum(xy)/2
+ xc <- sum((x[-n,1] + x[-1,1]) * xy)/A/6
+ yc <- sum((x[-n,2] + x[-1,2]) * xy)/A/6
+ structure(c(xc, yc), names = colnames(x))
+ }
+ areas <- sapply(object, function(x) polyarea(x))
+ cnts <- sapply(object, function(x) polycentre(x))
+ rbind(cnts, `Area` = areas)
+}
Modified: branches/1.15/inst/ChangeLog
===================================================================
--- branches/1.15/inst/ChangeLog 2009-08-26 15:34:44 UTC (rev 956)
+++ branches/1.15/inst/ChangeLog 2009-08-26 15:58:07 UTC (rev 957)
@@ -52,6 +52,9 @@
* added poolaccum & estaccumR with associated functions and
updates (rev 913 to 923).
+ * merged summary.ordihull & summary.ordiellipse: centres and areas
+ of plotted hulls or ellipses.
+
Version 1.15-3 (released June 17, 2009)
* merged revs 866 to 868: changed the way capscale displays
Modified: branches/1.15/man/ordihull.Rd
===================================================================
--- branches/1.15/man/ordihull.Rd 2009-08-26 15:34:44 UTC (rev 956)
+++ branches/1.15/man/ordihull.Rd 2009-08-26 15:58:07 UTC (rev 957)
@@ -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{
@@ -20,10 +22,10 @@
\code{\link{ordiplot}}.
}
\usage{
-ordihull(ord, groups, display = "sites", draw = c("lines","polygon"),
+ordihull(ord, groups, display = "sites", draw = c("lines","polygon", "none"),
show.groups, label = FALSE, ...)
ordiellipse(ord, groups, display="sites", kind = c("sd","se"), conf,
- draw = c("lines","polygon"), w = weights(ord, display),
+ draw = c("lines","polygon", "none"), w = weights(ord, display),
show.groups, label = FALSE, ...)
ordispider(ord, groups, display="sites", w = weights(ord, display),
show.groups, ...)
@@ -49,14 +51,16 @@
\item{draw}{Use either \code{\link{lines}} or \code{\link{polygon}} to
draw the
line. Graphical parameters are passed to both. The main difference
- is that \code{polygon}s may be filled and non-transparent.}
+ is that \code{polygon}s may be filled and non-transparent. With \code{none}
+ nothing is drawn, but the function returns the \code{\link{invisible}}
+ plotting data.}
\item{show.groups}{Show only given groups. This can be a vector, or
\code{TRUE} if you want to show items for which condition is
\code{TRUE}. This argument makes it possible to use different
colours and line types for groups. The default is to show all
groups. }
- \item{label}{Label the centroid of the hull or the ellipse with the
- group name.}
+ \item{label}{Label the centre of the points in hull or the ellipse with
+ the group name.}
\item{startmark}{plotting characer used to mark the first
item. The default is to use no mark, and for instance,
\code{startmark = 1} will draw a circle. For other plotting characters,
@@ -97,6 +101,17 @@
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 centres of the ellipses or hulls and their
+ surface areas in user units. The centres of the hulls may differ
+ from the location of the \code{label} which is the centre of the
+ points instead of the centre of the polygon. With \code{draw = "none"}
+ only the result object is returned and nothing is drawn.
+
Function \code{ordiarrows} draws
\code{\link{arrows}} and \code{ordisegments} draws line
\code{\link{segments}} between successive items in the
@@ -143,13 +158,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