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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 13 17:33:52 CET 2011


Author: gsimpson
Date: 2011-01-13 17:33:52 +0100 (Thu, 13 Jan 2011)
New Revision: 203

Modified:
   pkg/R/Stratiplot.R
   pkg/inst/ChangeLog
   pkg/man/Stratiplot.Rd
Log:
Stratiplot gains ability to handle absolute data

Modified: pkg/R/Stratiplot.R
===================================================================
--- pkg/R/Stratiplot.R	2011-01-13 16:06:23 UTC (rev 202)
+++ pkg/R/Stratiplot.R	2011-01-13 16:33:52 UTC (rev 203)
@@ -14,6 +14,8 @@
                                  rev.sort = FALSE,
                                  strip = FALSE,
                                  topPad = 6,
+                                 varTypes = "relative",
+                                 absoluteSize = 0.5,
                                  zoneNames = NULL,
                                  drawLegend = TRUE,
                                  ...) {
@@ -22,7 +24,8 @@
         if(isTRUE(all.equal(side, "top"))) {
             M <- function(lims) min(lims) + (diff(lims) / 2)
             xlim <- current.panel.limits()$xlim
-            panel.axis(side = side, outside = TRUE, at = 0, #M(xlim),
+            panel.axis(side = side, outside = TRUE, #at = 0,
+                       at = M(xlim),
                        tck = 1, line.col = "black",
                        text.col = "black",
                        labels = levels(sx$ind)[which.packet()],
@@ -91,13 +94,43 @@
         else
             c(minLim - (padY * diffy), maxLim + (padY * diffy))
     }
+    ## Reverse the y-axis?
     if(rev)
         ylim <- rev(ylim)
+    ## process the column/variable types
+    ## If varTypes of length one replicate it to NCOL(x)
+    if((typeLen <- length(varTypes)) != 1L) {
+        varTypes <- rep(varTypes, length = n.vars)
+        ## If typeLen != 1 or NCOL shout warning
+        if(typeLen != n.vars) {
+            warning("Length of 'varTypes' not 1 or equal to number of variables. Recycling or truncating of 'varTypes' as a result.")
+        }
+    }
+    ## Only allow two types of variables: "relative", "absolute"
+    if(any(!(varTypes%in% c("relative", "absolute"))))
+        stop("Ambiguous entry in 'varTypes'.\nMust be one of \"relative\", or \"absolute\"")
+    ## compute max abundances per relative column, which is used
+    ## to scale the panel widths layout.widths parameter)
     max.abun <- sapply(x, function(x) round(max(x), 1))
+    ## absolute panels should be set to absoluteSize of max.abun
+    panelWidths <- max.abun
+    ABS <- which(varTypes == "absolute")
+    REL <- which(varTypes == "relative")
+    panelWidths[ABS] <- absoluteSize * max(max.abun[REL])
+    ## xlim in xyplot call
     xlimits <- lapply(max.abun * 1.05, function(x) c(0, x))
+    if(any(ABS)) {
+        ## but need any "absolute" panels setting to +/- 0.05(range)
+        min.vars <- sapply(x[ABS], min)
+        max.vars <- sapply(x[ABS], max)
+        ranges <- (0.04 * (max.vars - min.vars))
+        xlimits[ABS] <- as.list(data.frame(t(cbind(min.vars - ranges,
+                                                   max.vars + ranges))))
+    }
+    ## scales in xyplot call
     scales <- list(cex = 0.75, tck = 0.75,
                    y = list(axs = "r", limits = ylim),
-                   x = list(axs = "r", rot = 45, relation = "free"))
+                   x = list(axs = "r", rot = 45, relation = "free", limits = xlimits))
     par.strip.text <- list(cex = 0.75)
     str.max <- 1
     if(!isTRUE(strip)) {
@@ -152,11 +185,11 @@
            strip.left = FALSE, strip = strip,
            par.strip.text = par.strip.text,
            scales = scales,
-           xlim = xlimits,
+           ##xlim = xlimits,
            ylim = ylim,
            panel = "panel.Stratiplot",
            layout = c(n.vars, 1, pages),
-           par.settings = list(layout.widths = list(panel = max.abun),
+           par.settings = list(layout.widths = list(panel = panelWidths),#max.abun),
            layout.heights = list(top.padding = str.max)),
            axis = if(isTRUE(strip)) {axis.default} else {axis.VarLabs},
            legend = Legend,

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2011-01-13 16:06:23 UTC (rev 202)
+++ pkg/inst/ChangeLog	2011-01-13 16:33:52 UTC (rev 203)
@@ -22,6 +22,14 @@
 	demarcate the zone boundaries are drawn and labelled using
 	argument 'zoneNames'.
 
+	First attempt to allow both relative (percentages or proportions)
+	and absolute variables, or mixtures thereof, in a single plot. The
+	user is free to specify which variables should be treated as relative
+	or absolute, and variables marked as absolute will be drawn with
+	fixed-width panels, the size of which can be controlled via argument
+	'absoluteSize' (default is 0.5 * largest panel width). Consider
+	this functionality unstable at the moment.
+
 	* residLen: was not 'join'-ing the training set and passive data
 	correctly and would fail if species were found in one but not the
 	other data set.

Modified: pkg/man/Stratiplot.Rd
===================================================================
--- pkg/man/Stratiplot.Rd	2011-01-13 16:06:23 UTC (rev 202)
+++ pkg/man/Stratiplot.Rd	2011-01-13 16:33:52 UTC (rev 203)
@@ -16,6 +16,7 @@
 \method{Stratiplot}{default}(x, y, type = "l", ylab = NULL, xlab = "",
            pages = 1, rev = TRUE, ylim, sort = c("none", "wa", "var"),
            svar = NULL, rev.sort = FALSE, strip = FALSE, topPad =6,
+           varTypes = "relative", absoluteSize = 0.5,
            zoneNames = NULL, drawLegend = TRUE, \dots)
 
 \method{Stratiplot}{formula}(formula, data, subset, na.action, type = "l",
@@ -75,6 +76,19 @@
     actual space required can be automagically calculated from the
     variable names themselves. The currently gets most of the way there,
     but \code{topPad} is used to add some extra space if required.}
+  \item{varTypes}{a character vector of length 1 or equal in length to
+    the number of variables plotted. If length 1, the vector is expanded
+    to the required length. Two values are allowed; i.
+    \code{"relative"}, and ii. \code{"absolute"}. \code{"relative"}
+    treats the indicated variable as a percentage type variable and the
+    panel width is scaled relative to the percentage type variables
+    plotted. \code{"absolute"} treats the indicated variable as an
+    absolute variable whose panel width should be independent of the
+    other panels. Use \code{"absolute"} for variables that are not
+    species compositional data or other percentage type data.}
+  \item{absoluteSize}{numeric, length 1. This controls the width of
+    panels for variables marked as \code{"absolute"}, and is the
+    proportion of the largest non-\code{"absolute"} panel.}
   \item{zoneNames}{character vector of labels, one per zone, with which
     to label the zone legend, if drawn (see argument
     \code{drawLegend}). See Details.} 
@@ -84,8 +98,11 @@
     \code{\link[lattice]{xyplot}} function.}
 }
 \details{
-  Currently the function is designed for relative abundance data
-  only. Greater flexibility is planned in a future version.
+  The function now includes preliminary code to handle both relative
+  (proportional or percentage data) and absolute data types, and
+  mixtures thereof. Mixtures can be specified by supplying a vector of
+  types to \code{varTypes}, in the same order as the variables are drawn
+  on the plot.
 
   Plots can be specified symbolically using a formula. A typical model
   has the form \code{Y ~ variables}, where \code{Y} is either the core



More information about the Analogue-commits mailing list