[Analogue-commits] r303 - in pkg: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 18 03:40:41 CET 2013
Author: gsimpson
Date: 2013-03-18 03:40:39 +0100 (Mon, 18 Mar 2013)
New Revision: 303
Added:
pkg/R/lines.prcurve.R
Modified:
pkg/R/plot.prcurve.R
pkg/man/plot.prcurve.Rd
Log:
add lines.prcurve, modify arguments to plot.prcurve
Added: pkg/R/lines.prcurve.R
===================================================================
--- pkg/R/lines.prcurve.R (rev 0)
+++ pkg/R/lines.prcurve.R 2013-03-18 02:40:39 UTC (rev 303)
@@ -0,0 +1,15 @@
+lines.prcurve <- function(x, data, axes = 1:2, 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)
+ if(segments)
+ 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,
+ ...)
+ invisible()
+}
Modified: pkg/R/plot.prcurve.R
===================================================================
--- pkg/R/plot.prcurve.R 2013-01-16 22:06:10 UTC (rev 302)
+++ pkg/R/plot.prcurve.R 2013-03-18 02:40:39 UTC (rev 303)
@@ -1,9 +1,9 @@
## plot a principle curve in PCA space
plot.prcurve <- function(x, data, axes = 1:2,
- seg = TRUE,
+ segments = TRUE,
+ col = "red",
col.seg = "forestgreen",
- col.curve = "red",
- lwd.curve = 2, ...) {
+ lwd = 2, lwd.seg = 1, ...) {
scl <- 0
ordi <- rda(data)
pred <- predict(ordi, x$s, type = "wa", scaling = scl)[,axes]
@@ -14,8 +14,8 @@
plot(ordi, display = "sites", scaling = scl, type = "n",
xlim = xlim, ylim = ylim, choices = axes, ...)
points(scrs, ...)
- if(seg)
+ if(segments)
segments(scrs[,1], scrs[,2], pred[,1], pred[,2],
- col = col.seg)
- lines(pred[x$tag, 1:2], lwd = lwd.curve, col = col.curve)
+ col = col.seg, lwd = lwd.seg)
+ lines(pred[x$tag, 1:2], lwd = lwd, col = col, ...)
}
Modified: pkg/man/plot.prcurve.Rd
===================================================================
--- pkg/man/plot.prcurve.Rd 2013-01-16 22:06:10 UTC (rev 302)
+++ pkg/man/plot.prcurve.Rd 2013-03-18 02:40:39 UTC (rev 303)
@@ -1,5 +1,6 @@
\name{plot.prcurve}
\alias{plot.prcurve}
+\alias{lines.prcurve}
\title{
Plot a fitted principal curve in PCA space
}
@@ -8,8 +9,13 @@
underlying data in a biplot.
}
\usage{
-\method{plot}{prcurve}(x, data, axes = 1:2, seg = TRUE, col.seg = "forestgreen",
- col.curve = "red", lwd.curve = 2, ...)
+\method{plot}{prcurve}(x, data, axes = 1:2, segments = TRUE,
+ col = "red", col.seg = "forestgreen", lwd = 2,
+ lwd.seg = 1, ...)
+
+\method{lines}{prcurve}(x, data, axes = 1:2, segments = TRUE,
+ col = "red", col.seg = "forestgreen", lwd = 2,
+ lwd.seg = 1, ...)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
@@ -17,12 +23,13 @@
\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.}
- \item{seg}{logical; should segments be drawn between the observed
+ \item{segments}{logical; should segments be drawn between the observed
points to the location on the principal curve on to which they
- project.}
+ project.}
+ \item{col}{The colour to draw the principal curve in.}
\item{col.seg}{The colour to draw the segments in.}
- \item{col.curve}{The colour to draw the principal curve in.}
- \item{lwd.curve}{The line thickness used to draw the principal curve.}
+ \item{lwd, lwd.seg}{The line thickness used to draw the
+ principal curve and segments respectively.}
\item{\dots}{additional arguments passed on to \code{points} when
drawing the observations in PCA space.}
}
@@ -39,9 +46,11 @@
\author{
Gavin L. Simpson
}
-%\note{
-%% ~~further notes~~
-%}
+\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 }{....} ~
@@ -58,11 +67,17 @@
## Fit the principal curve using varying complexity of smoothers
## for each species
-aber.pc2 <- prcurve(abernethy2, method = "ca", trace = TRUE,
- vary = TRUE, penalty = 1.4)
+aber.pc <- prcurve(abernethy2, method = "ca", trace = TRUE,
+ vary = TRUE, penalty = 1.4)
## Plot the curve
-plot(aber.pc2, abernethy2)
+plot(aber.pc, abernethy2)
+
+## 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)
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
More information about the Analogue-commits
mailing list