en:customized_functions:ordicenter
ordicenter
Author: David Zelený
Function which adds group centroids onto ordination diagram. The code heavily borrows from the vegan
function ordispider
, written by Jari Oksanen. Use of ordicenter
(including the names of its arguments) has the same logic (for details about the arguments and use, consult help to ordispider
function).
See here for examples how to use this function.
- ordicenter.r
ordicenter <- function (ord, groups, display = "sites", w = weights(ord, display), show.groups, ...) { weights.default <- function(object, ...) NULL pts <- scores(ord, display = display, ...) w <- eval(w) if (length(w) == 1) w <- rep(1, nrow(pts)) if (is.null(w)) w <- rep(1, nrow(pts)) if (!missing(show.groups)) { take <- groups %in% show.groups pts <- pts[take, , drop = FALSE] groups <- groups[take] w <- w[take] } out <- seq(along = groups) inds <- names(table(groups)) for (is in inds) { gr <- out[groups == is] if (length(gr) > 1) { X <- pts[gr, ] W <- w[gr] ave <- apply(X, 2, weighted.mean, w = W) vegan:::ordiArgAbsorber(ave[1], ave[2], labels = is, FUN = text, ...) } if (length(gr) == 1) { X <- pts[gr, ] W <- w[gr] vegan:::ordiArgAbsorber(X[1], X[2], labels = is, FUN = text, ...) } } invisible() }
en/customized_functions/ordicenter.txt · Last modified: 2017/10/11 20:36 by 127.0.0.1