Skip to content

Commit

Permalink
Merge branch 'ordiplot-plot.cca-cex'
Browse files Browse the repository at this point in the history
  • Loading branch information
jarioksa committed Jun 9, 2024
2 parents f7f68a0 + e5b23a1 commit 50154ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
23 changes: 14 additions & 9 deletions R/ordiplot.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
`ordiplot` <-
function (ord, choices = c(1, 2), type = "points", display, xlim,
ylim, cex = 0.7, ...)
ylim, ...)
{
## local functions to absorb non-par arguments of plot.default
localPoints <- function(..., log, frame.plot, panel.first,
Expand All @@ -10,9 +10,9 @@
if (inherits(ord, "decorana") || inherits(ord, "cca")) {
if (missing(display))
out <- plot(ord, choices = choices, type = type, xlim = xlim,
ylim = ylim, cex = cex, ...)
ylim = ylim, ...)
else out <- plot(ord, choices = choices, type = type, display = display,
xlim = xlim, ylim = ylim, cex = cex, ...)
xlim = xlim, ylim = ylim, ...)
}
else {
type <- match.arg(type, c("points", "text", "none"))
Expand Down Expand Up @@ -45,9 +45,9 @@
stop("no scores found: nothing to plot")
## Use linestack and exit if there is only one dimension
if (NCOL(X) == 1 && NCOL(Y) == 1) {
pl <- linestack(X, ylim = range(c(X,Y), na.rm=TRUE), cex = cex, ...)
pl <- linestack(X, ylim = range(c(X,Y), na.rm=TRUE), ...)
if (!is.null(Y))
linestack(Y, side = "left", add = TRUE, cex = cex, ...)
linestack(Y, side = "left", add = TRUE, ...)
return(invisible(pl))
}
tmp <- apply(rbind(X, Y), 2, range, na.rm=TRUE)
Expand All @@ -57,11 +57,16 @@
ylim <- tmp[, 2]
plot(tmp, xlim = xlim, ylim = ylim, asp = 1, type = "n",
...)
## default cex = 0.7 if not defined by the user
if (is.null(match.call(expand.dots = FALSE)$...$cex)) {
op <- par(cex = 0.7)
on.exit(par(op))
}
if (type == "points") {
if (!is.null(X))
localPoints(X, pch = 1, col = 1, cex = cex, ...)
localPoints(X, pch = 1, col = 1, ...)
if (!is.null(Y))
localPoints(Y, pch = "+", col = "red", cex = cex, ...)
localPoints(Y, pch = "+", col = "red", ...)
}
if (type == "text") {
if (!is.null(X)) {
Expand All @@ -70,15 +75,15 @@
warning("type='t', but no names available: using x1...")
labs <- paste0("x", as.character(seq_len(nrow(X))))
}
localText(X, labels = labs, col = 1, cex = cex, ...)
localText(X, labels = labs, col = 1, ...)
}
if (!is.null(Y)) {
labs <- rownames(Y)
if (is.null(labs)) {
warning("type='t', but no names available: using y1...")
labs <- paste0("y", as.character(seq_len(nrow(Y))))
}
localText(Y, labels = labs, col = "red", cex = cex, ...)
localText(Y, labels = labs, col = "red", ...)
}
}
out <- list(sites = X, species = Y)
Expand Down
20 changes: 10 additions & 10 deletions R/plot.decorana.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"plot.decorana" <-
function (x, choices = c(1, 2), origin = TRUE, display = c("both",
"sites", "species", "none"), cex = 0.8, cols = c(1, 2), type, xlim, ylim,
...)
`plot.decorana` <-
function (x, choices = c(1, 2), origin = TRUE,
display = c("both", "sites", "species", "none"), cex = 0.7,
cols = c(1, 2), type, xlim, ylim, ...)
{
display <- match.arg(display)
sites <- x$rproj
specs <- x$cproj
if (missing(type)) {
nitlimit <- 120
nit <- 0
if (display == "sites" || display == "both")
if (display == "sites" || display == "both")
nit <- nit + nrow(sites)
if (display == "species" || display == "both")
if (display == "species" || display == "both")
nit <- nit + nrow(specs)
if (nit > nitlimit)
if (nit > nitlimit)
type <- "points"
else type <- "text"
}
Expand Down Expand Up @@ -50,7 +50,7 @@
if (missing(xlim)) xlim <- range(sp.x, st.x)
if (missing(ylim)) ylim <- range(sp.y, st.y)
})
plot(sites, type = "n", xlim = xlim, ylim = ylim, asp = 1,
plot(sites, type = "n", xlim = xlim, ylim = ylim, asp = 1,
...)
if (origin) {
abline(h = 0, lty = 3)
Expand All @@ -61,12 +61,12 @@
abline(v = x$origin[choices[1]], lty = 3)
}
if (type != "none" && (display == "both" || display == "sites")) {
if (type == "text" && !is.null(sitnam))
if (type == "text" && !is.null(sitnam))
text(sites, sitnam, cex = cex, col = cols[1])
else points(sites, cex = cex, col = cols[1])
}
if (type != "none" && (display == "both" || display == "species")) {
if (type == "text" && !is.null(spenam))
if (type == "text" && !is.null(spenam))
text(specs, spenam, cex = cex, col = cols[2])
else points(specs, pch = "+", cex = cex, col = cols[2])
}
Expand Down
2 changes: 1 addition & 1 deletion man/decorana.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ decorana(veg, iweigh=0, iresc=4, ira=0, mk=26, short=0,

\method{plot}{decorana}(x, choices=c(1,2), origin=TRUE,
display=c("both","sites","species","none"),
cex = 0.8, cols = c(1,2), type, xlim, ylim, ...)
cex = 0.7, cols = c(1,2), type, xlim, ylim, ...)

\method{text}{decorana}(x, display = c("sites", "species"), labels,
choices = 1:2, origin = TRUE, select, ...)
Expand Down
11 changes: 1 addition & 10 deletions man/ordiplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
}

\usage{
ordiplot(ord, choices = c(1, 2), type="points", display, xlim, ylim,
cex = 0.7, ...)
ordiplot(ord, choices = c(1, 2), type="points", display, xlim, ylim, ...)
\method{points}{ordiplot}(x, what, select, arrows = FALSE,
length = 0.05, arr.mul, ...)
\method{text}{ordiplot}(x, what, labels, select, arrows = FALSE,
Expand All @@ -38,7 +37,6 @@ ordiplot(ord, choices = c(1, 2), type="points", display, xlim, ylim,
\code{\link{rda}}, \code{\link{dbrda}} and \code{\link{capscale}}
it is the same as in \code{\link{plot.cca}}. }
\item{xlim, ylim}{the x and y limits (min,max) of the plot.}
\item{cex}{Character expansion factor for points and text.}
\item{\dots}{Other graphical parameters. }
\item{x}{A result object from \code{ordiplot}.}
\item{what}{Items identified in the ordination plot. The types depend
Expand Down Expand Up @@ -107,13 +105,6 @@ ordiplot(ord, choices = c(1, 2), type="points", display, xlim, ylim,
\author{
Jari Oksanen
}
\note{
The purpose of these functions is to provide similar functionality as
the \code{plot}, \code{plotid} and \code{specid} methods in library
\code{labdsv}. The functions are somewhat limited in parametrization,
but you can call directly the standard \code{\link{identify}} and
\code{\link{plot}} functions for a better user control.
}

\seealso{ \code{\link{identify}} for basic operations, \code{\link{plot.cca}},
\code{\link{plot.decorana}}, \code{\link{plot.procrustes}} which also
Expand Down

0 comments on commit 50154ab

Please sign in to comment.