[Analogue-commits] r350 - in pkg: R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 22 00:50:59 CEST 2013


Author: gsimpson
Date: 2013-07-22 00:50:59 +0200 (Mon, 22 Jul 2013)
New Revision: 350

Modified:
   pkg/R/lines.prcurve.R
   pkg/R/plot.prcurve.R
   pkg/inst/ChangeLog
   pkg/man/plot.prcurve.Rd
Log:
improvements to plot and lines methods following addition of components ordination and data to object returned from prcurve

Modified: pkg/R/lines.prcurve.R
===================================================================
--- pkg/R/lines.prcurve.R	2013-07-21 20:50:38 UTC (rev 349)
+++ pkg/R/lines.prcurve.R	2013-07-21 22:50:59 UTC (rev 350)
@@ -1,13 +1,13 @@
-lines.prcurve <- function(x, data, axes = 1:2, segments = TRUE,
+lines.prcurve <- function(x, axes = 1:2, scaling = 0, segments = TRUE,
                           col = "red", col.seg = "forestgreen",
                           lwd = 2, lwd.seg = 1,
                           ...) {
-  scl <- 0
-  ordi <- rda(data)
-  pred <- predict(ordi, x$s, type = "wa", scaling = scl)[, axes]
-  scrs <- scores(ordi, display = "sites", scaling = scl, choices = axes)
+  pred <- predict(x$ordination, x$s, type = "wa",
+                  scaling = scaling)[, axes]
+  scrs <- scores(x$ordination, display = "sites", scaling = scaling,
+                 choices = axes)
   if(segments)
-    segments(scrs[, 1], scrs[, 2], pred[, 1], pred[, 2], 
+    segments(scrs[, 1], scrs[, 2], pred[, 1], pred[, 2],
              col = col.seg, lwd = lwd.seg)
   lines(pred[x$tag, 1:2], lwd = lwd, col = col,
         ...)

Modified: pkg/R/plot.prcurve.R
===================================================================
--- pkg/R/plot.prcurve.R	2013-07-21 20:50:38 UTC (rev 349)
+++ pkg/R/plot.prcurve.R	2013-07-21 22:50:59 UTC (rev 350)
@@ -1,17 +1,17 @@
 ## plot a principle curve in PCA space
-plot.prcurve <- function(x, data, axes = 1:2,
+plot.prcurve <- function(x, axes = 1:2,
+                         scaling = 0,
                          segments = TRUE,
                          col = "red",
                          col.seg = "forestgreen",
                          lwd = 2, lwd.seg = 1, ...) {
-    scl <- 0
-    ordi <- rda(data)
-    pred <- predict(ordi, x$s, type = "wa", scaling = scl)[,axes]
-    scrs <- scores(ordi, display = "sites", scaling = scl,
+    pred <- predict(x$ordination, x$s, type = "wa",
+                    scaling = scaling)[,axes]
+    scrs <- scores(x$ordination, display = "sites", scaling = scaling,
                    choices = axes)
     xlim <- range(scrs[,1], pred[,1])
     ylim <- range(scrs[,2], pred[,2])
-    plot(ordi, display = "sites", scaling = scl, type = "n",
+    plot(x$ordination, display = "sites", scaling = scaling, type = "n",
          xlim = xlim, ylim = ylim, choices = axes, ...)
     points(scrs, ...)
     if(segments)

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2013-07-21 20:50:38 UTC (rev 349)
+++ pkg/inst/ChangeLog	2013-07-21 22:50:59 UTC (rev 350)
@@ -26,10 +26,23 @@
 	estimates of smooth complexities. Residual variance printed to
 	fewer decimal places.
 
+	Now returns components `ordination` and `data`, the PCA ordination
+	(resulting from `rda()`) and the original data used to fit the
+	curve, respectively. This simplifies the `plot` and `lines`
+	methods for example.
+
 	* residuals.prcurve: new `residuals` method for principal curves
 	extracting or computing various types of residual for a fitted
 	curve.
 
+	* plot.prcurve, lines.prcurve: much improved following the
+	addition of new components in the object returned by `prcurve`.
+	No longer need to supply the original data used to fit the curve.
+
+	The scaling to use for the plot can now be specified via new
+	argument `scaling`. This makes the `lines` method more broadly
+	useful.
+
 	* Streamlined some of the documentation to avoid runnning the same
 	code many times.
 

Modified: pkg/man/plot.prcurve.Rd
===================================================================
--- pkg/man/plot.prcurve.Rd	2013-07-21 20:50:38 UTC (rev 349)
+++ pkg/man/plot.prcurve.Rd	2013-07-21 22:50:59 UTC (rev 350)
@@ -9,20 +9,24 @@
 underlying data in a biplot.
 }
 \usage{
-\method{plot}{prcurve}(x, data, axes = 1:2, segments = TRUE,
+\method{plot}{prcurve}(x, axes = 1:2, scaling = 0, segments = TRUE,
      col = "red", col.seg = "forestgreen", lwd = 2,
      lwd.seg = 1, ...)
 
-\method{lines}{prcurve}(x, data, axes = 1:2, segments = TRUE,
+\method{lines}{prcurve}(x, axes = 1:2, scaling = 0, segments = TRUE,
       col = "red", col.seg = "forestgreen", lwd = 2,
       lwd.seg = 1, ...)
 }
 %- maybe also 'usage' for other objects documented here.
 \arguments{
   \item{x}{an object of class \code{"prcurve"}.}
-  \item{data}{The data the principal curve was fitted to.}
   \item{axes}{numeric vector of length 2; this is passed to the
-    \code{choices} argument of the \code{\link[vegan]{scores}} function.}
+    \code{choices} argument of the \code{\link[vegan]{scores}}
+    function.}
+  \item{scaling}{numeric; the scaling to use. See
+    \code{\link{scores.rda}} for the available options. The default is
+    not to scale the scores, but \code{scaling = 1} might be a useful
+    alternative.}
   \item{segments}{logical; should segments be drawn between the observed
     points to the location on the principal curve on to which they
     project.}
@@ -46,11 +50,11 @@
 \author{
 Gavin L. Simpson
 }
-\note{
-  Note that all plotting is done using \code{scaling == 0} at the
-  moment, and as such the \code{lines()} method only makes sense when
-  added to an underlying PCA in the same scaling. See the Examples.
-}
+%% \note{
+%%   Note that all plotting is done using \code{scaling == 0} at the
+%%   moment, and as such the \code{lines()} method only makes sense when
+%%   added to an underlying PCA in the same scaling. See the Examples.
+%% }
 
 %% ~Make other sections like Warning with \section{Warning }{....} ~
 
@@ -71,13 +75,13 @@
                    vary = TRUE, penalty = 1.4)
 
 ## Plot the curve
-plot(aber.pc, abernethy2)
+plot(aber.pc)
 
 ## The lines() method can be used to add the principal curve to an
 ## existing plot
 ord <- rda(abernethy2)
-plot(ord)
-lines(aber.pc, data = abernethy2)
+plot(ord, scaling = 1)
+lines(aber.pc, scaling = 1)
 }
 % Add one or more standard keywords, see file 'KEYWORDS' in the
 % R documentation directory.



More information about the Analogue-commits mailing list