[Vegan-commits] r1160 - in branches/1.17: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 3 09:11:50 CET 2010


Author: gsimpson
Date: 2010-03-03 09:11:50 +0100 (Wed, 03 Mar 2010)
New Revision: 1160

Modified:
   branches/1.17/R/screeplot.cca.R
   branches/1.17/R/screeplot.prcomp.R
   branches/1.17/R/screeplot.princomp.R
   branches/1.17/man/screeplot.cca.Rd
Log:
merge r1137 to 1.17.x branch

Modified: branches/1.17/R/screeplot.cca.R
===================================================================
--- branches/1.17/R/screeplot.cca.R	2010-03-02 18:19:47 UTC (rev 1159)
+++ branches/1.17/R/screeplot.cca.R	2010-03-03 08:11:50 UTC (rev 1160)
@@ -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: branches/1.17/R/screeplot.prcomp.R
===================================================================
--- branches/1.17/R/screeplot.prcomp.R	2010-03-02 18:19:47 UTC (rev 1159)
+++ branches/1.17/R/screeplot.prcomp.R	2010-03-03 08:11:50 UTC (rev 1160)
@@ -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: branches/1.17/R/screeplot.princomp.R
===================================================================
--- branches/1.17/R/screeplot.princomp.R	2010-03-02 18:19:47 UTC (rev 1159)
+++ branches/1.17/R/screeplot.princomp.R	2010-03-03 08:11:50 UTC (rev 1160)
@@ -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: branches/1.17/man/screeplot.cca.Rd
===================================================================
--- branches/1.17/man/screeplot.cca.Rd	2010-03-02 18:19:47 UTC (rev 1159)
+++ branches/1.17/man/screeplot.cca.Rd	2010-03-03 08:11:50 UTC (rev 1160)
@@ -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