[Analogue-commits] r271 - in pkg: . R inst man tests/Examples
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 25 14:21:58 CEST 2012
Author: gsimpson
Date: 2012-07-25 14:21:57 +0200 (Wed, 25 Jul 2012)
New Revision: 271
Modified:
pkg/DESCRIPTION
pkg/R/Stratiplot.R
pkg/inst/ChangeLog
pkg/man/Stratiplot.Rd
pkg/tests/Examples/analogue-Ex.Rout.save
Log:
fix NA-handling issue in Stratiplot.default, bump to 0.9-7, fix example .Rout.save
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2012-07-24 20:04:43 UTC (rev 270)
+++ pkg/DESCRIPTION 2012-07-25 12:21:57 UTC (rev 271)
@@ -1,7 +1,7 @@
Package: analogue
Type: Package
Title: Analogue and weighted averaging methods for palaeoecology
-Version: 0.9-6
+Version: 0.9-7
Date: $Date$
Depends: R (>= 2.15.0), stats, graphics, vegan (>= 1.17-12), lattice, grid,
MASS, princurve, mgcv
Modified: pkg/R/Stratiplot.R
===================================================================
--- pkg/R/Stratiplot.R 2012-07-24 20:04:43 UTC (rev 270)
+++ pkg/R/Stratiplot.R 2012-07-25 12:21:57 UTC (rev 271)
@@ -18,6 +18,7 @@
absoluteSize = 0.5,
zoneNames = NULL,
drawLegend = TRUE,
+ na.action = "na.omit",
...) {
## inline function for custom axis
axis.VarLabs <- function(side, ...) {
@@ -43,6 +44,7 @@
## ylabel
if(is.null(ylab))
ylab <- deparse(substitute(y))
+
## do we need to sort variables
if(missing(sort))
sort <- "none"
@@ -63,9 +65,13 @@
}
if(rev.sort)
ord <- rev(ord)
+ ## apply ordering
x <- x[, ord]
+
+ ## stack the data
sx <- stack(x)
- sx$ind <- factor(sx$ind, levels = colnames(x))
+ sx$ind <- factor(sx$ind, levels = colnames(x)) # add grouping variable
+
## check length of y
if(!isTRUE(all.equal((leny <- length(y)), (nr <- nrow(sx))))) {
## if length(y) == nrow(sx)/n.vars, then expand
@@ -74,6 +80,16 @@
else
stop("Ambiguous 'length(y)';\nmust be equal to 'nrow(x)' or\n'nrow(x) / number of species'.")
}
+
+ ## handle NA's, by default NA pass in here fine, but this messes
+ ## up line plots or polygons for example
+ NAFUN <- match.fun(na.action)
+ sx <- NAFUN(sx)
+ ## and apply to `y` too
+ if(!is.null(NAS <- na.action(sx))) {
+ y <- y[-NAS]
+ }
+
## plot parameters
maxy <- max(y, na.rm = TRUE)
miny <- min(y, na.rm = TRUE)
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2012-07-24 20:04:43 UTC (rev 270)
+++ pkg/inst/ChangeLog 2012-07-25 12:21:57 UTC (rev 271)
@@ -1,5 +1,21 @@
analogue Change Log
+Version 0.9-7
+
+ * Stratiplot: In 0.9-5 a change was made to stop stripping NAs
+ when using the formula interface. This means a way of dealing with
+ NAs in the default plotting method is required especially when
+ plotting using lines or poylgons, as Lattice will honour the NA
+ and draw lines and polygons with gaps.
+
+ Stratiplot.default gains argument `na.action` which defaults to
+ `"na.omit"`. Note this is different to the formula method where
+ we *want* NAs to propogate through to the default method for
+ plotting.
+
+ This change allows for datasets collected on different sediment
+ intervals from the same core to be combined in a single diagram.
+
Version 0.9-6
* caterpillarPlot: now no longer draws a box round the plot.
Modified: pkg/man/Stratiplot.Rd
===================================================================
--- pkg/man/Stratiplot.Rd 2012-07-24 20:04:43 UTC (rev 270)
+++ pkg/man/Stratiplot.Rd 2012-07-25 12:21:57 UTC (rev 271)
@@ -17,7 +17,8 @@
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)
+ zoneNames = NULL, drawLegend = TRUE, na.action = "na.omit",
+ \dots)
\method{Stratiplot}{formula}(formula, data, subset,
na.action = "na.pass", type = "l",
@@ -45,8 +46,11 @@
\item{subset}{an optional vector specifying a subset of observations
to be used in the fitting process.}
\item{na.action}{a function which indicates what should happen when
- the data contain \code{NA}s. The default is \code{"na.pass"} which
- results in \code{NA} being passed on to the plotting functions.}
+ the data contain \code{NA}s. The default is \code{"na.omit"} for the
+ default method, which strips \code{NA}s from the stacked data,
+ whereas the default for the formula method is \code{"na.pass"} which
+ results in \code{NA} being passed on to the plotting function. See
+ Details for further information.}
\item{ylab, xlab}{the x- and y-axis labels.}
\item{pages}{numeric; the number of pages to draw the plot over. May
be useful for data sets with many species.}
@@ -111,15 +115,30 @@
standard, notation for formulae apply, such as model formulae used in
\code{\link{lm}}.
- The default for argument \code{na.action} is \code{"na.pass"}, which
- results in any \code{NA} values being passed on to the plotting
- code. This allows for plotting of proxies that been measured on
- different levels of the stratigraphy. Should you wish to have
- \code{NA} removed from the data before plotting, use \code{na.action =
- "na.omit"}, though do note this will remove all rows where any
- column/variable takes the value \code{NA}. See Examples for an
- illustration of these two techniques.
+ For the formula method the default for argument \code{na.action} is
+ \code{"na.pass"}, which results in any \code{NA} values being passed
+ on to the plotting code. This allows for plotting of proxies that been
+ measured on different levels of the stratigraphy. Should you wish to
+ have \code{NA} removed from the data before plotting, use
+ \code{na.action = "na.omit"}, though do note this will remove all rows
+ where any column/variable takes the value \code{NA}. The default
+ \code{Stratiplot} method, which is used by the formula method for
+ plotting, will strip any \code{NA} values from the data provided to
+ it. This allows the function to correctly handle the situation where
+ proxies are measured on different levels of the core \emph{and} you
+ are displaying the data using lines of polygons. If the \code{NA} were
+ not dropped by \code{Stratiplot.default}, any \code{NA} values would
+ show up as breaks in the line or polygon drawn for each panel.
+ In summary, the two methods have different defaults for
+ \code{na.action} to allow them to handle proxies measured on different
+ levels of the same core. This does mean that you can not use the
+ formula interface \strong{and} strip NA's at the
+ \code{Stratiplot.default} level. If you need that level of control use
+ \code{Stratiplot.default} directly by not providing a formula as
+ argument \code{x} and by supplying data for the y-axis via argument
+ \code{y}. See Examples for an illustration of these features.
+
Note that \code{formula} is \strong{not} passed on to
\code{\link[lattice]{xyplot}}. Instead, the formula is parsed and
evaluated within \code{Stratiplot} and an appropriate data structure
@@ -204,6 +223,26 @@
## to remove rows with NA, use 'na.action = "na.omit"'
(Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p"),
na.action = "na.omit"))
+
+## Example of two proxies measured on different levels of core
+## (Here measurements on alternate levels)
+set.seed(5)
+dat2a <- data.frame(Depth = seq(1, by = 2, length = 20), LOI = runif(20))
+dat2b <- data.frame(Depth = seq(0, by = 2, length = 20), TC = runif(20))
+dat2 <- join(dat2a, dat2b, na.replace = FALSE, split = FALSE)
+dat2 <- dat2[order(dat2$Depth), ]
+head(dat2)
+
+## Default is to allow NA through formula, but drop them when plotting
+(Stratiplot(Depth ~ LOI + TC, data = dat2, type = c("l","p")))
+
+## compare with this if we didn't suppress NA in default Stratiplot
+## method (can't use formula interface for this yet
+(Stratiplot(dat2[,-1], dat2[,1], type = c("l","p"),
+ na.action = "na.pass"))
+## Notice no lines are draw as there a no "sections" ithout missing
+## levels. If you want/desire this behaviour then you can't use formula
+## interface yet as there is no way to specify the na.action separately
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
Modified: pkg/tests/Examples/analogue-Ex.Rout.save
===================================================================
--- pkg/tests/Examples/analogue-Ex.Rout.save 2012-07-24 20:04:43 UTC (rev 270)
+++ pkg/tests/Examples/analogue-Ex.Rout.save 2012-07-25 12:21:57 UTC (rev 271)
@@ -1,5 +1,5 @@
-R version 2.15.0 Patched (2012-04-14 r59019) -- "Easter Beagle"
+R version 2.15.0 Patched (2012-04-16 r59049) -- "Easter Beagle"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)
@@ -24,14 +24,14 @@
> library('analogue')
Loading required package: vegan
Loading required package: permute
-This is vegan 2.0-3
+This is vegan 2.0-4
Loading required package: lattice
Loading required package: grid
Loading required package: MASS
Loading required package: princurve
Loading required package: mgcv
-This is mgcv 1.7-13. For overview type 'help("mgcv-package")'.
-This is analogue 0.9-5
+This is mgcv 1.7-18. For overview type 'help("mgcv-package")'.
+This is analogue 0.9-7
>
> assign(".oldSearch", search(), pos = 'CheckExEnv')
> cleanEx()
@@ -303,8 +303,35 @@
> (Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p"),
+ na.action = "na.omit"))
>
+> ## Example of two proxies measured on different levels of core
+> ## (Here measurements on alternate levels)
+> set.seed(5)
+> dat2a <- data.frame(Depth = seq(1, by = 2, length = 20), LOI = runif(20))
+> dat2b <- data.frame(Depth = seq(0, by = 2, length = 20), TC = runif(20))
+> dat2 <- join(dat2a, dat2b, na.replace = FALSE, split = FALSE)
+> dat2 <- dat2[order(dat2$Depth), ]
+> head(dat2)
+ Depth LOI TC
+110 0 NA 0.8902071
+1 1 0.2002145 NA
+21 2 NA 0.7207010
+2 3 0.6852186 NA
+31 4 NA 0.2113403
+3 5 0.9168758 NA
>
+> ## Default is to allow NA through formula, but drop them when plotting
+> (Stratiplot(Depth ~ LOI + TC, data = dat2, type = c("l","p")))
>
+> ## compare with this if we didn't suppress NA in default Stratiplot
+> ## method (can't use formula interface for this yet
+> (Stratiplot(dat2[,-1], dat2[,1], type = c("l","p"),
++ na.action = "na.pass"))
+> ## Notice no lines are draw as there a no "sections" ithout missing
+> ## levels. If you want/desire this behaviour then you can't use formula
+> ## interface yet as there is no way to specify the na.action separately
+>
+>
+>
> cleanEx()
> nameEx("abernethy")
> ### * abernethy
@@ -1173,6 +1200,7 @@
> ## customisation
> opttol <-
+ caterpillarPlot(ImbrieKipp, SumSST, col = "red2", bg = "yellow",
++ lcol = "blue",
+ xlab = expression(Summer~Sea~Surface~Temperature~(degree*C)))
>
> ## invisibly returns the optima and tolerances
@@ -4911,25 +4939,25 @@
wa> ## residuals for the training set
wa> residuals(mod4)
V14.61 V17.196 V18.110 V16.227 V14.47 V23.22
--3.89845110 -0.95914237 -0.57577610 0.83646773 -1.12654866 1.85855684
+-3.89845110 -0.95914236 -0.57577610 0.83646773 -1.12654865 1.85855684
V2.12 V23.29 V12.43 R9.7 A157.3 V23.81
- 4.93907447 -1.56332718 1.02901346 -2.01091600 0.72379238 -2.30397581
+ 4.93907447 -1.56332718 1.02901346 -2.01091601 0.72379237 -2.30397582
V23.82 V12.53 V23.83 V12.56 A152.84 V16.50
--1.16893885 -1.90464620 0.99721686 -1.39764003 1.29346295 -0.29234573
+-1.16893886 -1.90464621 0.99721685 -1.39764003 1.29346294 -0.29234573
V22.122 V16.41 V4.32 V12.66 V19.245 V4.8
- 2.13000056 -4.44031822 -0.92783840 0.99172654 -1.49152689 1.88724026
+ 2.13000055 -4.44031821 -0.92783839 0.99172654 -1.49152688 1.88724027
A180.15 V18.34 V20.213 V19.222 A180.39 V16.189
- 2.78850048 -0.63727536 0.33475037 -0.01275751 -1.65993109 -2.09930701
+ 2.78850049 -0.63727536 0.33475038 -0.01275751 -1.65993108 -2.09930701
V12.18 V7.67 V17.165 V19.310 V16.190 A153.154
--0.97538682 2.31383514 1.87380535 2.64327583 0.01900071 0.13747169
+-0.97538682 2.31383515 1.87380536 2.64327583 0.01900072 0.13747169
V19.308 V22.172 V10.98 V22.219 V16.33 V22.204
--0.26612390 -2.21647192 2.40270758 0.25826513 -1.69856608 0.20738893
+-0.26612390 -2.21647192 2.40270759 0.25826513 -1.69856608 0.20738893
V20.167 V10.89 V12.79 V19.216 V14.90 A180.72
-0.92731700 -0.84954530 -0.55321548 0.80956624 0.66973330 0.70524398
V16.21 A180.76 V15.164 A180.78 V14.5 V3.128
-0.23696237 -0.14589252 -0.26826158 0.54819699 -0.32786314 1.64879299
A179.13 V9.31 V20.230 V20.7 V20.234 V18.21
- 1.53212230 0.96958483 0.44047759 -0.17038549 -0.21308146 -0.39014885
+ 1.53212229 0.96958483 0.44047759 -0.17038549 -0.21308146 -0.39014886
V12.122
0.72061292
>
@@ -6046,25 +6074,25 @@
wa> ## residuals for the training set
wa> residuals(mod4)
V14.61 V17.196 V18.110 V16.227 V14.47 V23.22
--3.89845110 -0.95914237 -0.57577610 0.83646773 -1.12654866 1.85855684
+-3.89845110 -0.95914236 -0.57577610 0.83646773 -1.12654865 1.85855684
V2.12 V23.29 V12.43 R9.7 A157.3 V23.81
- 4.93907447 -1.56332718 1.02901346 -2.01091600 0.72379238 -2.30397581
+ 4.93907447 -1.56332718 1.02901346 -2.01091601 0.72379237 -2.30397582
V23.82 V12.53 V23.83 V12.56 A152.84 V16.50
--1.16893885 -1.90464620 0.99721686 -1.39764003 1.29346295 -0.29234573
+-1.16893886 -1.90464621 0.99721685 -1.39764003 1.29346294 -0.29234573
V22.122 V16.41 V4.32 V12.66 V19.245 V4.8
- 2.13000056 -4.44031822 -0.92783840 0.99172654 -1.49152689 1.88724026
+ 2.13000055 -4.44031821 -0.92783839 0.99172654 -1.49152688 1.88724027
A180.15 V18.34 V20.213 V19.222 A180.39 V16.189
- 2.78850048 -0.63727536 0.33475037 -0.01275751 -1.65993109 -2.09930701
+ 2.78850049 -0.63727536 0.33475038 -0.01275751 -1.65993108 -2.09930701
V12.18 V7.67 V17.165 V19.310 V16.190 A153.154
--0.97538682 2.31383514 1.87380535 2.64327583 0.01900071 0.13747169
+-0.97538682 2.31383515 1.87380536 2.64327583 0.01900072 0.13747169
V19.308 V22.172 V10.98 V22.219 V16.33 V22.204
--0.26612390 -2.21647192 2.40270758 0.25826513 -1.69856608 0.20738893
+-0.26612390 -2.21647192 2.40270759 0.25826513 -1.69856608 0.20738893
V20.167 V10.89 V12.79 V19.216 V14.90 A180.72
-0.92731700 -0.84954530 -0.55321548 0.80956624 0.66973330 0.70524398
V16.21 A180.76 V15.164 A180.78 V14.5 V3.128
-0.23696237 -0.14589252 -0.26826158 0.54819699 -0.32786314 1.64879299
A179.13 V9.31 V20.230 V20.7 V20.234 V18.21
- 1.53212230 0.96958483 0.44047759 -0.17038549 -0.21308146 -0.39014885
+ 1.53212229 0.96958483 0.44047759 -0.17038549 -0.21308146 -0.39014886
V12.122
0.72061292
>
@@ -7254,25 +7282,25 @@
> ## residuals for the training set
> residuals(mod4)
V14.61 V17.196 V18.110 V16.227 V14.47 V23.22
--3.89845110 -0.95914237 -0.57577610 0.83646773 -1.12654866 1.85855684
+-3.89845110 -0.95914236 -0.57577610 0.83646773 -1.12654865 1.85855684
V2.12 V23.29 V12.43 R9.7 A157.3 V23.81
- 4.93907447 -1.56332718 1.02901346 -2.01091600 0.72379238 -2.30397581
+ 4.93907447 -1.56332718 1.02901346 -2.01091601 0.72379237 -2.30397582
V23.82 V12.53 V23.83 V12.56 A152.84 V16.50
--1.16893885 -1.90464620 0.99721686 -1.39764003 1.29346295 -0.29234573
+-1.16893886 -1.90464621 0.99721685 -1.39764003 1.29346294 -0.29234573
V22.122 V16.41 V4.32 V12.66 V19.245 V4.8
- 2.13000056 -4.44031822 -0.92783840 0.99172654 -1.49152689 1.88724026
+ 2.13000055 -4.44031821 -0.92783839 0.99172654 -1.49152688 1.88724027
A180.15 V18.34 V20.213 V19.222 A180.39 V16.189
- 2.78850048 -0.63727536 0.33475037 -0.01275751 -1.65993109 -2.09930701
+ 2.78850049 -0.63727536 0.33475038 -0.01275751 -1.65993108 -2.09930701
V12.18 V7.67 V17.165 V19.310 V16.190 A153.154
--0.97538682 2.31383514 1.87380535 2.64327583 0.01900071 0.13747169
+-0.97538682 2.31383515 1.87380536 2.64327583 0.01900072 0.13747169
V19.308 V22.172 V10.98 V22.219 V16.33 V22.204
--0.26612390 -2.21647192 2.40270758 0.25826513 -1.69856608 0.20738893
+-0.26612390 -2.21647192 2.40270759 0.25826513 -1.69856608 0.20738893
V20.167 V10.89 V12.79 V19.216 V14.90 A180.72
-0.92731700 -0.84954530 -0.55321548 0.80956624 0.66973330 0.70524398
V16.21 A180.76 V15.164 A180.78 V14.5 V3.128
-0.23696237 -0.14589252 -0.26826158 0.54819699 -0.32786314 1.64879299
A179.13 V9.31 V20.230 V20.7 V20.234 V18.21
- 1.53212230 0.96958483 0.44047759 -0.17038549 -0.21308146 -0.39014885
+ 1.53212229 0.96958483 0.44047759 -0.17038549 -0.21308146 -0.39014886
V12.122
0.72061292
>
@@ -7422,7 +7450,7 @@
> ### * <FOOTER>
> ###
> cat("Time elapsed: ", proc.time() - get("ptime", pos = 'CheckExEnv'),"\n")
-Time elapsed: 18.804 0.233 19.688 0 0
+Time elapsed: 16.322 0.207 16.69 0 0
> grDevices::dev.off()
null device
1
More information about the Analogue-commits
mailing list