[Vegan-commits] r1137 - in pkg/vegan: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Feb 21 16:01:43 CET 2010
Author: gsimpson
Date: 2010-02-21 16:01:42 +0100 (Sun, 21 Feb 2010)
New Revision: 1137
Modified:
pkg/vegan/R/screeplot.cca.R
pkg/vegan/R/screeplot.prcomp.R
pkg/vegan/R/screeplot.princomp.R
pkg/vegan/man/screeplot.cca.Rd
Log:
Add option to draw a legend in screeplot methods
Modified: pkg/vegan/R/screeplot.cca.R
===================================================================
--- pkg/vegan/R/screeplot.cca.R 2010-02-19 06:44:08 UTC (rev 1136)
+++ pkg/vegan/R/screeplot.cca.R 2010-02-21 15:01:42 UTC (rev 1137)
@@ -3,7 +3,7 @@
npcs = min(10, if(is.null(x$CCA)) x$CA$rank else x$CCA$rank),
ptype = "o", bst.col = "red", bst.lty = "solid",
xlab = "Component", ylab = "Inertia",
- main = deparse(substitute(x)), ...)
+ main = deparse(substitute(x)), legend = bstick, ...)
{
if(is.null(x$CCA))
eig.vals <- x$CA$eig
@@ -27,11 +27,14 @@
if(type=="barplot") {
## barplot looks weird if 0 not included
ylims <- range(0, ylims)
- mids <- barplot(eig.vals[comps], names = names(eig.vals[comps]),
- main = main, ylab = ylab, ylim = ylims, ...)
+ mids <- barplot(eig.vals[comps],
+ names = names(eig.vals[comps]),
+ main = main, ylab = ylab, ylim = ylims,
+ ...)
} else {
- plot(eig.vals[comps], type = ptype, axes = FALSE, ylim = ylims,
- xlab = xlab, ylab = ylab, main = main, ...)
+ plot(eig.vals[comps], type = ptype, axes = FALSE,
+ ylim = ylims, xlab = xlab, ylab = ylab,
+ main = main, ...)
axis(2)
axis(1, at = comps, labels = names(eig.vals[comps]))
box()
@@ -40,6 +43,33 @@
if(bstick) {
lines(mids, ord.bstick[comps], type = ptype, col = bst.col,
lty = bst.lty)
+ if(legend) {
+ dot.args <- list(...)
+ dot.nams <- names(dot.args)
+ pch <- if("pch" %in% dot.nams)
+ dot.args$pch
+ else
+ par("pch")
+ col <- if("col" %in% dot.nams)
+ dot.args$col
+ else
+ par("col")
+ lty <- if("lty" %in% dot.nams)
+ dot.args$lty
+ else
+ par("lty")
+ if(type == "lines") {
+ legend("topright",
+ legend = c("Ordination","Broken Stick"),
+ bty = "n", col = c(col, bst.col),
+ lty = c(lty, bst.lty),
+ pch = pch)
+ } else {
+ legend("topright",
+ legend = "Broken Stick", bty = "n",
+ col = bst.col, lty = bst.lty, pch = pch)
+ }
+ }
}
invisible(xy.coords(x = mids, y = eig.vals[comps]))
}
Modified: pkg/vegan/R/screeplot.prcomp.R
===================================================================
--- pkg/vegan/R/screeplot.prcomp.R 2010-02-19 06:44:08 UTC (rev 1136)
+++ pkg/vegan/R/screeplot.prcomp.R 2010-02-21 15:01:42 UTC (rev 1137)
@@ -2,7 +2,7 @@
function(x, bstick = FALSE, type = c("barplot", "lines"),
npcs = min(10, length(x$sdev)), ptype = "o", bst.col = "red",
bst.lty = "solid", xlab = "Component", ylab = "Inertia",
- main = deparse(substitute(x)), ...)
+ main = deparse(substitute(x)), legend = bstick, ...)
{
main
type <- match.arg(type)
@@ -35,6 +35,33 @@
if(bstick) {
lines(mids, ord.bstick[comps], type = ptype, col = bst.col,
lty = bst.lty)
+ if(legend) {
+ dot.args <- list(...)
+ dot.nams <- names(dot.args)
+ pch <- if("pch" %in% dot.nams)
+ dot.args$pch
+ else
+ par("pch")
+ col <- if("col" %in% dot.nams)
+ dot.args$col
+ else
+ par("col")
+ lty <- if("lty" %in% dot.nams)
+ dot.args$lty
+ else
+ par("lty")
+ if(type == "lines") {
+ legend("topright",
+ legend = c("Ordination","Broken Stick"),
+ bty = "n", col = c(col, bst.col),
+ lty = c(lty, bst.lty),
+ pch = pch)
+ } else {
+ legend("topright",
+ legend = "Broken Stick", bty = "n",
+ col = bst.col, lty = bst.lty, pch = pch)
+ }
+ }
}
invisible(xy.coords(x = mids, y = eig.vals[comps]))
}
Modified: pkg/vegan/R/screeplot.princomp.R
===================================================================
--- pkg/vegan/R/screeplot.princomp.R 2010-02-19 06:44:08 UTC (rev 1136)
+++ pkg/vegan/R/screeplot.princomp.R 2010-02-21 15:01:42 UTC (rev 1137)
@@ -4,7 +4,7 @@
npcs = min(10, length(x$sdev)),
ptype = "o", bst.col = "red", bst.lty = "solid",
xlab = "Component", ylab = "Inertia",
- main = deparse(substitute(x)), ...)
+ main = deparse(substitute(x)), legend = bstick, ...)
{
main
type <- match.arg(type)
@@ -35,6 +35,33 @@
if(bstick) {
lines(mids, ord.bstick[comps], type = ptype, col = bst.col,
lty = bst.lty)
+ if(legend) {
+ dot.args <- list(...)
+ dot.nams <- names(dot.args)
+ pch <- if("pch" %in% dot.nams)
+ dot.args$pch
+ else
+ par("pch")
+ col <- if("col" %in% dot.nams)
+ dot.args$col
+ else
+ par("col")
+ lty <- if("lty" %in% dot.nams)
+ dot.args$lty
+ else
+ par("lty")
+ if(type == "lines") {
+ legend("topright",
+ legend = c("Ordination","Broken Stick"),
+ bty = "n", col = c(col, bst.col),
+ lty = c(lty, bst.lty),
+ pch = pch)
+ } else {
+ legend("topright",
+ legend = "Broken Stick", bty = "n",
+ col = bst.col, lty = bst.lty, pch = pch)
+ }
+ }
}
invisible(xy.coords(x = mids, y = eig.vals[comps]))
}
Modified: pkg/vegan/man/screeplot.cca.Rd
===================================================================
--- pkg/vegan/man/screeplot.cca.Rd 2010-02-19 06:44:08 UTC (rev 1136)
+++ pkg/vegan/man/screeplot.cca.Rd 2010-02-21 15:01:42 UTC (rev 1137)
@@ -20,7 +20,7 @@
npcs = min(10, if (is.null(x$CCA)) x$CA$rank else x$CCA$rank),
ptype = "o", bst.col = "red", bst.lty = "solid",
xlab = "Component", ylab = "Inertia",
- main = deparse(substitute(x)),
+ main = deparse(substitute(x)), legend = bstick,
\dots)
\method{screeplot}{decorana}(x, bstick = FALSE, type = c("barplot", "lines"),
@@ -34,14 +34,14 @@
npcs = min(10, length(x$sdev)),
ptype = "o", bst.col = "red", bst.lty = "solid",
xlab = "Component", ylab = "Inertia",
- main = deparse(substitute(x)),
+ main = deparse(substitute(x)), legend = bstick,
\dots)
\method{screeplot}{princomp}(x, bstick = FALSE, type = c("barplot", "lines"),
npcs = min(10, length(x$sdev)),
ptype = "o", bst.col = "red", bst.lty = "solid",
xlab = "Component", ylab = "Inertia",
- main = deparse(substitute(x)),
+ main = deparse(substitute(x)), legend = bstick,
\dots)
bstick(n, \dots)
@@ -67,6 +67,7 @@
\item{bst.col, bst.lty}{the colour and line type used to draw the
broken stick distribution.}
\item{xlab, ylab, main}{graphics parameters.}
+ \item{legend}{logical; draw a legend?}
\item{n}{an object from which the variances can be extracted or the
number of variances (components) in the case of
\code{bstick.default}.}
More information about the Vegan-commits
mailing list