Stratiplot | R Documentation |
Draws palaeoecological stratigraphic diagrams of one or more variables as a function of depth/age, with the time dimension flowing from the bottom to the top of the y-axis, using the Lattice graphics package.
Stratiplot(x, ...)
## Default S3 method:
Stratiplot(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, na.action = "na.omit",
labelValues = NULL, labelAt = NULL, labelRot = 60, yticks,
...)
## S3 method for class 'formula'
Stratiplot(formula, data, subset,
na.action = "na.pass", type = "l",
ylab = NULL, xlab = "", pages = 1, ...)
x |
matrix-like object; the variables to be plotted. |
y |
numeric vector of depths/ages corresponding to rows in
|
formula |
an object of class |
type |
character; The type of plotting. Can be a vector. Note
that not all Lattice ‘type’s are supported and some new types
are allowed. See |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
na.action |
a function which indicates what should happen when
the data contain |
ylab , xlab |
the x- and y-axis labels. |
pages |
numeric; the number of pages to draw the plot over. May be useful for data sets with many species. |
rev |
logical; should the y-axis limits be reversed |
ylim |
user supplied limits for the y-axis (time/depth). If not
supplied, suitable limits will be determined from the data. As such,
in general use |
sort |
character; how should the variables (columns) of |
svar |
vector; optional variable to sort columns of |
rev.sort |
logical; should the sorting order be reversed. |
strip |
logical; Should panels have strips containing variable
labels drawn on them? Default is |
topPad |
numeric; additional padding for the top axis to
accomodate long variable names. This is a temporary fudge until the
actual space required can be automagically calculated from the
variable names themselves. The currently gets most of the way there,
but |
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.
|
absoluteSize |
numeric, length 1. This controls the width of
panels for variables marked as |
zoneNames |
character vector of labels, one per zone, with which
to label the zone legend, if drawn (see argument
|
drawLegend |
logical; should a legend for the zones |
labelValues |
a vector of labels for the variables
plotted. Should be equal in length to the number or variables in the
resulting plot. The main use for |
labelAt , labelRot |
these control the placement and rotation,
respectively, of the variable labels. |
yticks |
This is passed to the |
... |
additional arguments passed to
|
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 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 Y ~ variables
, where Y
is either the core
depths or sample ages/dates (to be plotted on the y-axis) and
variables
is a series of terms which specifies the variables to
plot against Y
. Terms should be specified with the form
var1 + var2 + var3
to plot only those variables. Other,
standard, notation for formulae apply, such as model formulae used in
lm
.
For the formula method the default for argument na.action
is
"na.pass"
, which results in any 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 NA
removed from the data before plotting, use
na.action = "na.omit"
, though do note this will remove all rows
where any column/variable takes the value NA
. The default
Stratiplot
method, which is used by the formula method for
plotting, will strip any 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 and you
are displaying the data using lines of polygons. If the NA
were
not dropped by Stratiplot.default
, any 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
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 and strip NA's at the
Stratiplot.default
level. If you need that level of control use
Stratiplot.default
directly by not providing a formula as
argument x
and by supplying data for the y-axis via argument
y
. See Examples for an illustration of these features.
Note that formula
is not passed on to
xyplot
. Instead, the formula is parsed and
evaluated within Stratiplot
and an appropriate data structure
formed to facilitate plotting via xyplot
. As
such, the special features of Lattice formulae cannot be used.
If zones are drawn on the stratigraphic plot, the zoneNames
argument can be used to supply a set of names with which to label the
zones using a legend. This legend is drawn on the right-hand side of
the the straigraphic diagram if drawLegend = TRUE
is
supplied. The zoneNames
must be supplied in stratigraphic
order, as that is the order in which they are drawn in the
legend. Whether this ordering is reversed or not will depend on the
value of argument rev
. It is up to the user to provide the
labels in the correct order. Zones are specified by the zone
boundaries (excluding the core sequence top and bottom), and as a
result 1 more label is required than the number of zone boundaries
supplied. If no zoneNames
is not supplied, but a legend is
requested, suitable names will be produced. If you do not wish to have
any labelling at all, then set zoneNames = ""
as this will get
recycled to the correct length. See the Example section for an
illustration of how this drawing zones works.
A side effect of calling Stratiplot
is that a plot is drawn on
the currently active device. A Lattice plot object of class
"trellis"
is returned invisibly. This is a change from pre
0.17-0 version of the package.
The function currently doesn't know about ages/dates and will interpret these as ‘depths’ instead. This will be fixed in a future version.
Gavin L. Simpson.
xyplot
,
panel.Stratiplot
, panel.Loess
.
data(V12.122)
Depths <- as.numeric(rownames(V12.122))
(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("h","l","g","smooth")))
## Order taxa by WA in depth --- ephasises change over time
(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("h"), sort = "wa"))
## Using the default interface
spp.want <- c("O.univ","G.ruber","G.tenel","G.pacR")
(plt <- Stratiplot(V12.122[, spp.want], y = Depths,
type = c("poly", "g")))
## Adding zones to a Stratigraphic plot
## Default labelling and draw zone legend
## Here we choose 4 arbitrary Depths as the zone boundaries
set.seed(123)
Zones <-sample(Depths, 4)
Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("poly","g"),
zones = Zones)
## As before, but supplying your own zone labels
zone.labs <- c("A","B","C","D","E")
Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("poly","g"),
zones = Zones, zoneNames = zone.labs)
## Suppress the drawing of the zone legend
Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("poly","g"),
zones = Zones, drawLegend = FALSE)
## Add zones and draw a legend, but do not label the zones
Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("poly","g"),
zones = Zones, zoneNames = "")
## Show illustration of NA handling
set.seed(42)
dat <- data.frame(Depth = 1:20, LOI = runif(20), TC = NA)
dat <- within(dat, TC[sample(20, 10)] <- runif(10))
## default is 'na.action = "na.pass"'
Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p"))
## 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
## Works with matrices
M <- as.matrix(V12.122)
Stratiplot(M, Depths, type = c("h"))
## Custom variable labels using expressions
df <- data.frame(Age = 1:10, Var1 = rnorm(10), Var2 = rnorm(10),
Var3 = rnorm(10))
## Use a vector of expressions to label variables on plot
## See ?plotmath for syntax of expressions
exprs <- expression(delta^{15}*N, # label for Var1
delta^{18}*O, # label for Var2
delta^{13}*C) # label for Var3
Stratiplot(Age ~ ., data = df, labelValues = exprs, varTypes = "absolute")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.