Skip to content

Commit

Permalink
wcmdscale: scores() and plot() know of sppscores<-.wcmdscale
Browse files Browse the repository at this point in the history
  • Loading branch information
jarioksa committed Aug 13, 2024
1 parent 13a49e9 commit 68fbfe0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
47 changes: 32 additions & 15 deletions R/print.wcmdscale.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,43 @@
}

`scores.wcmdscale` <-
function(x, choices = NA, tidy = FALSE, ...)
function(x, choices = NA, display = "sites", tidy = FALSE, ...)
{
p <-
if (any(is.na(choices))) {
x$points
} else {
choices <- choices[choices <= NCOL(x$points)]
x$points[, choices, drop = FALSE]
if ("species" %in% names(x))
display <- match.arg(display, c("sites", "species"), several.ok = TRUE)
else
display <- match.arg(display, "sites")
p <- list()
for (sco in display) {
if (sco == "sites")
p[[sco]] <- x$points
else
p[[sco]] <- x[[sco]]
if (!anyNA(choices)) {
choices <- choices[choices <= NCOL(p[[sco]])]
p[[sco]] <- p[[sco]][, choices, drop = FALSE]
}
if (is.null(rownames(p)))
rownames(p) <- as.character(seq_len(nrow(p)))
if (tidy) {
p <- data.frame(p, "scores" = "sites", "label" = rownames(p),
"weight" = weights(x))
if (is.null(rownames(p[[sco]])))
rownames(sco) <- as.character(seq_len(nrow(p[[sco]])))
if (tidy) {
wts <- if(sco == "sites") weights(x) else NA
p[[sco]] <- data.frame(p[[sco]], "score" = sco,
"label" = rownames(p[[sco]]),
weights = wts)
}
}
if (tidy && length(display) > 1) {
p <- do.call("rbind", p)
rownames(p) <- p$label
}
p
if (length(p) == 1)
p[[1]]
else
p
}

`plot.wcmdscale` <-
function(x, choices = c(1,2), type = "t", ...)
function(x, choices = c(1,2), display = "sites", type = "t", ...)
{
ordiplot(x, display = "sites", choices = choices, type = type, ...)
ordiplot(x, display = display, choices = choices, type = type, ...)
}
9 changes: 6 additions & 3 deletions man/wcmdscale.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
\title{Weighted Classical (Metric) Multidimensional Scaling}
\usage{
wcmdscale(d, k, eig = FALSE, add = FALSE, x.ret = FALSE, w)
\method{plot}{wcmdscale}(x, choices = c(1, 2), type = "t", ...)
\method{scores}{wcmdscale}(x, choices = NA, tidy = FALSE, ...)
\method{plot}{wcmdscale}(x, choices = c(1, 2), display = "sites", type = "t", ...)
\method{scores}{wcmdscale}(x, choices = NA, display = "sites", tidy = FALSE, ...)
}
\description{
Weighted classical multidimensional scaling,
Expand All @@ -39,6 +39,9 @@ wcmdscale(d, k, eig = FALSE, add = FALSE, x.ret = FALSE, w)
called with options \code{eig = TRUE} or \code{x.ret = TRUE} (See
Details).}
\item{choices}{Axes to be returned; \code{NA} returns all real axes.}
\item{display}{Kind of scores. Normally only \code{"sites"} are
available, but \code{"species"} can be supplemented with
\code{\link{sppscores}}.}
\item{type}{Type of graph which may be \code{"t"}ext, \code{"p"}oints
or \code{"n"}one.}
\item{tidy}{Return scores that are compatible with \CRANpkg{ggplot2}:
Expand Down Expand Up @@ -120,7 +123,7 @@ wcmdscale(d, k, eig = FALSE, add = FALSE, x.ret = FALSE, w)
weights (hence name) and handles negative eigenvalues differently.
\code{\link{eigenvals.wcmdscale}} and
\code{\link{stressplot.wcmdscale}} are some specific methods. Species
scores can be added tothe result with \code{\link{sppscores}}. Other
scores can be added to the result with \code{\link{sppscores}}. Other
multidimensional scaling methods are \code{\link{monoMDS}}, and
\code{\link[MASS]{isoMDS}} and \code{\link[MASS]{sammon}} in package
\pkg{MASS}. }
Expand Down

0 comments on commit 68fbfe0

Please sign in to comment.