[Analogue-commits] r339 - in pkg: . R inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Jul 20 00:39:58 CEST 2013
Author: gsimpson
Date: 2013-07-20 00:39:58 +0200 (Sat, 20 Jul 2013)
New Revision: 339
Added:
pkg/R/plot3d.prcurve.R
pkg/man/plot3d.prcurve.Rd
Modified:
pkg/DESCRIPTION
pkg/NAMESPACE
pkg/inst/ChangeLog
Log:
add plot3d method for prcurve
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2013-07-19 22:38:44 UTC (rev 338)
+++ pkg/DESCRIPTION 2013-07-19 22:39:58 UTC (rev 339)
@@ -3,7 +3,7 @@
Title: Analogue and weighted averaging methods for palaeoecology
Version: 0.11-4
Date: $Date$
-Depends: R (>= 2.15.0), vegan (>= 1.17-12), princurve, lattice
+Depends: R (>= 2.15.0), vegan (>= 1.17-12), princurve, lattice, rgl
Imports: mgcv, MASS, stats, graphics, grid, brglm
Author: Gavin L. Simpson, Jari Oksanen
Maintainer: Gavin L. Simpson <gavin.simpson at uregina.ca>
Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE 2013-07-19 22:38:44 UTC (rev 338)
+++ pkg/NAMESPACE 2013-07-19 22:39:58 UTC (rev 339)
@@ -4,7 +4,7 @@
## Imports
##
## vegan
-importFrom(vegan, pasteCall, eigenvals, tolerance, scores)
+importFrom(vegan, pasteCall, eigenvals, tolerance, scores, ordirgl)
## mgcv
importFrom(mgcv, gam, s, smoothCon, mono.con, pcls, Predict.matrix)
## MASS
@@ -36,6 +36,11 @@
importFrom(brglm,
brglm,
brglm.control)
+## rgl
+importFrom(rgl,
+ plot3d,
+ lines3d,
+ decorate3d)
## Exports
export(analog,
@@ -202,6 +207,7 @@
S3method(plot, timetrack)
S3method(plot, wa)
S3method(plot, weightedCor)
+S3method(plot3d, prcurve)
S3method(reconPlot, default)
S3method(reconPlot, predict.mat)
S3method(reconPlot, predict.wa)
Added: pkg/R/plot3d.prcurve.R
===================================================================
--- pkg/R/plot3d.prcurve.R (rev 0)
+++ pkg/R/plot3d.prcurve.R 2013-07-19 22:39:58 UTC (rev 339)
@@ -0,0 +1,37 @@
+`plot3d.prcurve` <- function(x, data, scale = FALSE,
+ choices = 1:3, display = "sites",
+ scaling = 0,
+ lcol = "darkorange", lwd = 2,
+ decorate = TRUE,
+ xlab = NULL, ylab = NULL, zlab = NULL,
+ main = NULL, ...) {
+ ## check choices
+ if(!missing(choices)) {
+ lc <- length(choices)
+ if(lc > 3L) {
+ warning("More than 3 axes specified in 'choices', using the first 3.")
+ choices <- rep(choices, length.out = 3)
+ } else if(lc < 3L) {
+ warning("Fewer than 3 axes specified; reverting to defaults ('1:3')")
+ choices <- 1:3
+ }
+ }
+ ## do ordination
+ ord <- rda(data, scale = scale)
+ ## process labels
+ if(missing(xlab) || is.null(xlab))
+ xlab <- paste0("PC", choices[1])
+ if(missing(ylab) || is.null(ylab))
+ ylab <- paste0("PC", choices[2])
+ if(missing(zlab) || is.null(zlab))
+ zlab <- paste0("PC", choices[3])
+ ordirgl(ord, scaling = scaling, choices = choices, display = display,
+ ...)
+ pred <- predict(ord, x[["s"]], type = "wa",
+ scaling = scaling)[x[["tag"]], ]
+ lines3d(pred[,1], pred[,2], pred[,3], col = lcol, lwd = lwd, ...)
+ if(decorate) {
+ decorate3d(xlab = xlab, ylab = ylab, zlab = zlab, ...)
+ }
+ invisible()
+}
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2013-07-19 22:38:44 UTC (rev 338)
+++ pkg/inst/ChangeLog 2013-07-19 22:39:58 UTC (rev 339)
@@ -5,6 +5,9 @@
* logitreg: fitting is now possible using Firth's bias reduction
technique via the brglm package.
+ * plot3d.prcurve: dynamic 3D plot of the data in PCA space with
+ the fitted principal curve superimposed.
+
Version 0.11-3
* chooseTaxa: new argument `value` controls whether the data for
Added: pkg/man/plot3d.prcurve.Rd
===================================================================
--- pkg/man/plot3d.prcurve.Rd (rev 0)
+++ pkg/man/plot3d.prcurve.Rd 2013-07-19 22:39:58 UTC (rev 339)
@@ -0,0 +1,97 @@
+\name{plot3d.prcurve}
+\alias{plot3d.prcurve}
+
+\title{Interactive 3D plof of a principal curve in principal coordinate
+ space}
+\description{
+ Draws a 3D plot of the principal curve in principal coordinate space
+ using the \pkg{rgl} package and functions from \pkg{vegan}.
+}
+\usage{
+\method{plot3d}{prcurve}(x, data, scale = FALSE, choices = 1:3,
+ display = "sites", scaling = 0, lcol = "darkorange", lwd = 2,
+ decorate = TRUE, xlab = NULL, ylab = NULL, zlab = NULL,
+ main = NULL, ...)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{x}{
+ an object of class \code{"prcurve"} resulting from a call to
+ \code{\link{prcurve}}.
+ }
+ \item{data}{
+ the data used to fit the principal curve.
+ }
+ \item{scale}{
+ logical; should the variables in \code{data} be scaled to zero mean
+ and unit variance?
+ }
+ \item{choices}{
+ numeric vector of length 3; the ordination axes to plot.
+ }
+ \item{display}{
+ character; which scores to display. See \code{\link{scores.rda}}.
+ }
+ \item{scaling}{
+ numeric; the scaling to use for the scores. Default is no scaling.
+ }
+ \item{lcol, lwd}{
+ The colour and width, respectively, for the principal curve.
+ }
+ \item{decorate}{
+ logical; should the plot be decorated with bounding box, axes and
+ labels?
+ }
+ \item{xlab, ylab, zlab, main}{
+ Labels for the plot, to be drawn using \code{\link{decorate3d}}.
+ }
+ \item{\dots}{
+ Arguments passed to other functions. In particular, argments are
+ passed to \code{\link{ordirgl}}, \code{\link{lines3d}}, and
+ \code{\link{decorate3d}}.
+ }
+}
+%\details{
+%% ~~ If necessary, more details than the description above ~~
+%}
+\value{
+ A plot is drawn on the active RGL device. If there is no active RGL
+ device, one is opened upon plotting.
+}
+
+%\references{
+%% ~put references to the literature/web site here ~
+%}
+
+\author{
+ Gavin L. Simpson
+}
+
+%\note{
+%% ~~further notes~~
+%}
+
+%% ~Make other sections like Warning with \section{Warning }{....} ~
+
+\seealso{
+ \code{\link{ordirgl}}, \code{\link{prcurve}}, \code{decorate3d},
+ \code{\link{lines3d}}.
+}
+\examples{
+data(abernethy)
+
+## Remove the Depth and Age variables
+abernethy2 <- abernethy[, -(37:38)]
+
+## Fit the principal curve using the median complexity over
+## all species
+aber.pc <- prcurve(abernethy2, method = "ca", trace = TRUE,
+ vary = FALSE, penalty = 1.4)
+
+## 3D plot of data with curve superimposed
+plot3d(aber.pc, abernethy2)
+}
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ dynamic }
+\keyword{ graphics }% __ONLY ONE__ keyword per line
More information about the Analogue-commits
mailing list