[Vegan-commits] r2188 - in branches/2.0: R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat May 26 07:25:39 CEST 2012
Author: jarioksa
Date: 2012-05-26 07:25:38 +0200 (Sat, 26 May 2012)
New Revision: 2188
Modified:
branches/2.0/R/ordiellipse.R
branches/2.0/R/ordihull.R
branches/2.0/inst/ChangeLog
branches/2.0/inst/NEWS.Rd
branches/2.0/man/ordihull.Rd
Log:
merge r2173-6, 2185: semitransparent colours and label position in ordihull & ordiellipse
Modified: branches/2.0/R/ordiellipse.R
===================================================================
--- branches/2.0/R/ordiellipse.R 2012-05-24 19:39:33 UTC (rev 2187)
+++ branches/2.0/R/ordiellipse.R 2012-05-26 05:25:38 UTC (rev 2188)
@@ -1,7 +1,7 @@
-"ordiellipse" <-
+`ordiellipse` <-
function (ord, groups, display = "sites", kind = c("sd", "se"),
conf, draw = c("lines", "polygon", "none"),
- w = weights(ord, display), col = NULL,
+ w = weights(ord, display), col = NULL, alpha = 127,
show.groups, label = FALSE, ...)
{
weights.default <- function(object, ...) NULL
@@ -19,7 +19,10 @@
w <- rep(1, nrow(pts))
if (is.null(w))
w <- rep(1, nrow(pts))
- if (!missing(show.groups)) {
+ ## make semitransparent fill
+ if (draw == "polygon" && !is.null(col))
+ col <- rgb(t(col2rgb(col)), alpha = alpha, maxColorValue = 255)
+ if (!missing(show.groups)) {
take <- groups %in% show.groups
pts <- pts[take, , drop = FALSE]
groups <- groups[take]
Modified: branches/2.0/R/ordihull.R
===================================================================
--- branches/2.0/R/ordihull.R 2012-05-24 19:39:33 UTC (rev 2187)
+++ branches/2.0/R/ordihull.R 2012-05-26 05:25:38 UTC (rev 2188)
@@ -1,9 +1,23 @@
-"ordihull" <-
+`ordihull` <-
function (ord, groups, display = "sites",
draw = c("lines", "polygon", "none"),
- show.groups, label = FALSE, ...)
+ col = NULL, alpha = 127, show.groups, label = FALSE, ...)
{
draw <- match.arg(draw)
+ ## Internal function to find the polygon centre
+ 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
+ c(xc, yc)
+ }
+ ## Make semitransparent fill colour
+ if (draw == "polygon" && !is.null(col))
+ col <- rgb(t(col2rgb(col)), alpha = alpha, maxColorValue = 255)
pts <- scores(ord, display = display, ...)
if (!missing(show.groups)) {
take <- groups %in% show.groups
@@ -13,6 +27,8 @@
out <- seq(along = groups)
inds <- names(table(groups))
res <- list()
+ if (label)
+ cntrs <- names <- NULL
## Remove NA scores
kk <- complete.cases(pts)
for (is in inds) {
@@ -22,17 +38,25 @@
hpts <- chull(X)
hpts <- c(hpts, hpts[1])
if (draw == "lines")
- ordiArgAbsorber(X[hpts, ], FUN = lines, ...)
+ ordiArgAbsorber(X[hpts, ], FUN = lines,
+ col = if(is.null(col)) par("fg") else col, ...)
else if (draw == "polygon")
- ordiArgAbsorber(X[hpts,], FUN = polygon, ...)
+ ordiArgAbsorber(X[hpts,], FUN = polygon, col = col, ...)
if (label && draw != "none") {
- cntr <- colMeans(X)
- ordiArgAbsorber(cntr[1], cntr[2], labels = is,
- FUN = text, ...)
+ cntrs <- rbind(cntrs, polycentre(X[hpts,]))
+ names <- c(names, is)
}
res[[is]] <- X[hpts,]
}
}
+ if (label && draw != "none") {
+ if (draw == "lines")
+ ordiArgAbsorber(cntrs[,1], cntrs[,2], labels = names,
+ col = col, FUN = text, ...)
+ else
+ ordiArgAbsorber(cntrs, labels = names, col = NULL,
+ FUN = ordilabel, ...)
+ }
class(res) <- "ordihull"
invisible(res)
}
Modified: branches/2.0/inst/ChangeLog
===================================================================
--- branches/2.0/inst/ChangeLog 2012-05-24 19:39:33 UTC (rev 2187)
+++ branches/2.0/inst/ChangeLog 2012-05-26 05:25:38 UTC (rev 2188)
@@ -4,6 +4,8 @@
Version 2.0-4 (opened March 9, 2012)
+ * merge r2173-2176, 2185: ordihull labels, semintransparent
+ colours in ordihull & ordiellipse.
* merge r2170: bioenv accepts dissimilarities as input.
* merge r2167: warn about unequal aspect ratio in ordiplot3d.
* merge r2162: set equal axis scales for ordiplot3d.
Modified: branches/2.0/inst/NEWS.Rd
===================================================================
--- branches/2.0/inst/NEWS.Rd 2012-05-24 19:39:33 UTC (rev 2187)
+++ branches/2.0/inst/NEWS.Rd 2012-05-26 05:25:38 UTC (rev 2188)
@@ -52,6 +52,14 @@
\item \code{msoplot} is more configurable, and allows, for
instance, setting y-axis limits.
+ \item Hulls and ellipses are now filled using semitransparent
+ colours in \code{ordihull} and \code{ordiellipse}, and the
+ user can set the degree of transparency with a new argument
+ \code{alpha}. The filled shapes are used when these functions
+ are called with argument \code{draw = "polygon"}. Function
+ \code{ordihull} puts labels (with argument \code{label = TRUE})
+ now in the real polygon centre.
+
}
} % end new features
Modified: branches/2.0/man/ordihull.Rd
===================================================================
--- branches/2.0/man/ordihull.Rd 2012-05-24 19:39:33 UTC (rev 2187)
+++ branches/2.0/man/ordihull.Rd 2012-05-26 05:25:38 UTC (rev 2188)
@@ -19,10 +19,10 @@
\usage{
ordihull(ord, groups, display = "sites", draw = c("lines","polygon", "none"),
- show.groups, label = FALSE, ...)
+ col = NULL, alpha = 127, show.groups, label = FALSE, ...)
ordiellipse(ord, groups, display="sites", kind = c("sd","se"), conf,
draw = c("lines","polygon", "none"), w = weights(ord, display),
- col = NULL, show.groups, label = FALSE, ...)
+ col = NULL, alpha = 127, show.groups, label = FALSE, ...)
ordispider(ord, groups, display="sites", w = weights(ord, display),
show.groups, label = FALSE, ...)
ordicluster(ord, cluster, prune = 0, display = "sites",
@@ -43,6 +43,20 @@
non-transparent. With \code{none} nothing is drawn, but the
function returns the \code{\link{invisible}} plotting data.}
+ \item{col}{Colour of hull or ellipse lines (if \code{draw = "lines"})
+ or their fills (if \code{draw = "polygon"}) in \code{ordihull} and
+ \code{ordiellipse}. When \code{draw = "polygon"}, the colour of
+ bordering lines can be set with argument \code{border} of the
+ \code{\link{polygon}} function. For other functions the effect
+ depends on the underlining functions this argument is passed to.}
+
+ \item{alpha}{Transparency of the fill \code{col}our with \code{draw
+ = "polygon"} in \code{ordihull} and \code{ordiellipse}. The
+ argument takes precedence over possible transparency definitions
+ of the colour. The value must be in range \eqn{0...255}, and low
+ values are more transparent. Transparency is not available in all
+ graphics devices or file formats.}
+
\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
@@ -69,10 +83,6 @@
\item{cluster}{Result of hierarchic cluster analysis, such as
\code{\link{hclust}} or \code{\link[cluster]{agnes}}.}
- \item{col}{Colour of ellipses or ellipse fills in
- \code{ordiellipse}. For other functions the effect depends on the
- underlining functions this argument is passed to.}
-
\item{prune}{Number of upper level hierarchies removed from the
dendrogram. If \code{prune} \eqn{>0}, dendrogram will be
disconnected.}
@@ -139,10 +149,8 @@
returns a list of covariance matrices and scales used in drawing the
ellipses. These result objects have a \code{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.
+ their surface areas in user units. With \code{draw = "none"} only
+ the result object is returned and nothing is drawn.
}
@@ -178,7 +186,8 @@
ordicluster(mod, hclust(vegdist(dune)), prune=3, col = "blue")
plot(mod, type="n", display = "sites")
text(mod, display="sites", labels = as.character(Management))
-pl <- ordiellipse(mod, Management, kind="se", conf=0.95, lwd=2, col="blue")
+pl <- ordiellipse(mod, Management, kind="se", conf=0.95, lwd=2, draw = "polygon",
+ col="skyblue", border = "blue")
summary(pl)
}
\keyword{aplot }
More information about the Vegan-commits
mailing list