[Vegan-commits] r938 - in pkg/vegan: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Aug 22 14:09:48 CEST 2009
Author: jarioksa
Date: 2009-08-22 14:09:47 +0200 (Sat, 22 Aug 2009)
New Revision: 938
Modified:
pkg/vegan/R/ordihull.R
pkg/vegan/R/summary.ordihull.R
pkg/vegan/man/ordihull.Rd
Log:
ordihull finds now centre of the points, and summary.ordihull the centre of the polygon instead of the centre of the vertices
Modified: pkg/vegan/R/ordihull.R
===================================================================
--- pkg/vegan/R/ordihull.R 2009-08-22 05:42:42 UTC (rev 937)
+++ pkg/vegan/R/ordihull.R 2009-08-22 12:09:47 UTC (rev 938)
@@ -22,7 +22,7 @@
ordiArgAbsorber(X[hpts, ], FUN = lines, ...)
else ordiArgAbsorber(X[hpts,], FUN = polygon, ...)
if (label) {
- cntr <- colMeans(X[hpts[-1],])
+ cntr <- colMeans(X)
ordiArgAbsorber(cntr[1], cntr[2], labels = is,
FUN = text, ...)
}
Modified: pkg/vegan/R/summary.ordihull.R
===================================================================
--- pkg/vegan/R/summary.ordihull.R 2009-08-22 05:42:42 UTC (rev 937)
+++ pkg/vegan/R/summary.ordihull.R 2009-08-22 12:09:47 UTC (rev 938)
@@ -9,7 +9,18 @@
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) colMeans(x[-1,]))
- rbind(cnts, `Area` = areas)
+ altcnts <- sapply(object, function(x) polycentre(x))
+ rbind(cnts, altcnts, `Area` = areas)
}
Modified: pkg/vegan/man/ordihull.Rd
===================================================================
--- pkg/vegan/man/ordihull.Rd 2009-08-22 05:42:42 UTC (rev 937)
+++ pkg/vegan/man/ordihull.Rd 2009-08-22 12:09:47 UTC (rev 938)
@@ -57,8 +57,8 @@
\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,
@@ -104,8 +104,10 @@
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.
+ 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.
Function \code{ordiarrows} draws
\code{\link{arrows}} and \code{ordisegments} draws line
More information about the Vegan-commits
mailing list