Triangle plot functions for Lattice.
trianglePlot(x, data = NULL, ..., ref.cols = TRUE) #standard panels
panel.trianglePlot(x = NULL, y = NULL, a0 = NULL, b0 = NULL,
c0 = NULL, ..., loa.settings = FALSE, plot = TRUE,
process = TRUE)
panel.trianglePlotFrame(..., grid = NULL, axes = NULL)
panel.trianglePlotGrid(alim = NULL, blim = NULL, clim = NULL,
..., grid = TRUE, panel.scales = NULL)
panel.trianglePlotAxes(alim = NULL, blim = NULL, clim = NULL,
..., axes = TRUE, ticks=TRUE, annotation=TRUE,
panel.scales = NULL)
#other panels
panel.triangleByGroupPolygon(x = NULL, y = NULL, a0 = NULL,
b0 = NULL, c0 = NULL, ..., loa.settings = FALSE,
plot = TRUE, process = TRUE)
panel.triangleKernelDensity(x = NULL, y = NULL, a0 = NULL,
b0 = NULL, c0 = NULL, ..., loa.settings = FALSE,
plot = TRUE, process = TRUE)
panel.triangleSurfaceSmooth(x = NULL, y = NULL, z = NULL,
a0 = NULL, b0 = NULL, c0 = NULL, ..., loa.settings = FALSE,
plot = TRUE, process = TRUE)
#data handlers
triABC2XY(a, b = NULL, c = NULL, ..., force.abc = TRUE,
if.na = "remove.row", if.neg = "remove.row",
verbose = FALSE)
triXY2ABC(x, y = NULL, ..., force.xy = TRUE,
verbose = FALSE)
triLimsReset(ans)
triABCSquareGrid(a, b = NULL, c = NULL, ..., n=100)
trianglePlot
returns trellis objects, much like
conventional lattice
plot functions.
panel.trianglePlot...
functions are intended for use
within a trianglePlot
function call.
triABC2XY
returns a list containing the named
components x
and y
, which are the 2-D (x,y) transformations
of supplied (a,b,c) trianglePlot
elements.
triXY2ABC
returns a list containing the named
components a
, b
and c
, which are the (a,b,c)
triangle plot coordinates associated with supplied 2-D (x, y) that
trianglePlot
would generate.
resetTriLims
returns a supplied trellis object, rescaled
based on the assumption that it is a triangle plot.
For trianglePlot
only, a formula in structure
z ~ a0 + b0 + c0 | cond
. The elements a0
, b0
and c0
, the inputs for the three axis on the triangle plot,
are required, while z
and conditioning (cond
) are optional.
(For other functions, x
may be used as the pair to y
.
See y
below.)
For trianglePlot
only, if supplied, the assumed source
of the elements of formula x
, typically a data.frame
.
Additional arguments.
Either a logical to turn off/on grid color-coding or a
vector of colors to be applied to a0, b0 and c0 axes and grids. These are
applied to the grid lines and axes tick and annotation components. Some users,
particularly those less familiar with triangle plots, can find such color
referencing helpful when analyzing such plots. By default, the colorings are
quite subtle, so users can see the effect if them look for it but it does not
take over the plot when it is not focused on. Finer control can be achieved using
axes
, ticks
, grid
, etc. (See below).
(and x
in relevant functions). a/a0
, b/b0
and
c/c0
are the three scales of the triangle plot, and x
and y
are the equivalent 2-D projections. The arguments are typically options in panel functions
(panel...
functions), conversion functions (triABC2XY
and triXY2ABC
) and
the scaling function triLimsReset
. z
is the z-case from the plot formula.
loaPlot
arguments used to manage
panelPal
activity.
User-resets for the axes, grid, tick and annotation
elements of the plots. These can be NULL
or FALSE
to turn off, TRUE
to show,
a vector (in which case they are assumed to be color assignments) or a list of standard plot
parameters, e.g. col
, lty
, lwd
, etc. for color, line type and line thickness,
etc. Plot parameter assignments are applied to all axes unless specific axes are identified. For
example, trianglePlot
calls including grid.col = 2
make
all axes red, while calls including grid.a0.col = 2
only
recolor the first (a0) axis.
Delimiters for a, b and c scales, equivalent to xlim
and ylim
in conventional plots, but less flexible. See Details below for
more information.
A local argument, typically a list, that controls the
appearance of the a0/b0/c0 axes. This is roughly equivalent to the scales
argument used by conventional lattice
plots to handle x and y axis,
but intended for non-standard scales, such as the triangle axes used here.
It can be set directly or used in combination with the local scale(s) handler
function localScalesHandler
to override/hijack standard scales
operations. (See note below).
Logicals. If a list or data.frame is supplied
to triABC2XY
or triXY2ABC
as a source or a/b/c or x/y respectively
should appropriately named elements be used regardless of order? See Note below.
Character. Handling method to be used if NAs
are present.
The default option 'remove.row'
replaces all enteries in the same row with
NAs
. (Note: this is different from na.omit
which would
remove the whole row. Here, the row is retained as NAs
to maintain
indices for conditioning.) Other options currently include: 'make.zero'
to replace the NA
with 0
; and 'keep.as.is'
to leave
unchanged.
Character. Like if.na
but for negative values:
'remove.row'
to replace all enteries in the same row with
NAs
; 'make.zero'
to replace all negative values with
0
; 'rescale.col'
recales any column (i.e., a
, b
or
c
) that contains a negative from zero by subtracting the minimum.
Logical, default FALSE
. Should a full output be returned?
The alternative FALSE
generates a minimal report.
For triLimsReset
only, a trellis ouput, e.g. a lattice
plot,
to be scaled and plotted based on the assumption that it is a trianglePlot
.
For triABCSquareGrid
only, number of points to divide each axes by
when generating the data grid.
Karl Ropkins
trianglePlot
generates a triangle plot using the lattice framework.
panel.trianglePlot...
functions handle the appearance of triangle plot
outputs.
panel.trianglePlot
, which is assigned as the default panel
manages both the data layer of the plot and the plot frame (axes, grid, annotation,
etc).
panel.trianglePlotAxes
and panel.trianglePlotGrid
generate
axes and grid componets of the plot, and panel.trianglePlotFrame
is
a wrapper for these. The data layer, which by default is panel.loaPlot
,
can be accessed separately using the data.panel
argument.
triangleKernelDensity
generates a kernel density surface for supplied a0
,
b0
and c0
cases.
triangleSurfaceSmooth
generates a smoothed surface for supplied a0
,
b0
, c0
and z
cases.
triABC2XY
converts supplied (a, b, c) coordinates to an (x, y) scale suitable
for use with triangle plot functions.
triXY2ABC
converts supplied (x,y) coordinates from triangle plots to the associated
proportional (a, b, c) scale.
There are various options for range limiting with triABC2XY
, triXY2ABC
,
and therefore triangle plots. Firstly, limits can be set individually with
alim
, blim
and clim
, much like with xlim
and ylim
for
conventional plots. However, they can also be set at once using lims
, as in e.g.
lims = c(0, 1)
to set all axes to full ranges, or on the basis of minimum and maximum
cut-offs using abc.mins
and abc.maxs
, respectively.
trianglePlot
uses localScalesHandler
to override normal
lattice
handling of scales
. This allows parameters for axes other
than 'x'
and 'y'
to be passed via the scales
argument for
axis generation within the plot panel itself. The function does this by recovering
the information for each of the local axes (here a0
, b0
and c0
)
from scales
, and passing this on to the plot as the argument
panel.scales
which can then be evaluated by an appropriate panel...
function like panel.trianglePlotAxes
. At the same time it also resets
scales
to stop the standard axes being generated. The intention here is two-fold.
Firstly, to provide plot users with an axes control mechanism like the standard
scales
control of x
and y
that they already know. And, secondly,
to provide developers with a simple framework for the quick addition of non-standard axes
or scales. See localScalesHandler
and panel.localScale
for
further details.
trianglePlot
uses getPlotArgs
to manage lattice
defaults and
plot developer and user resets for the different plot components (axes, ticks, grid,
annotation). As with localScalesHandler
, the intention here is to provide more
routine access to higher level plot control.
These function makes extensive use of code developed by others.
Currently, several triangle plotting methods are under evaluation for use within this package. These are:
The tri-plot method of Graham and Mudgley:
Graham, David J. and Mudgley, Nicholas, G. Graphical representation of particle shape using triangular diagrams: An Excel spreadsheet method. Earth Surface Processes and Landforms, 25, 1473-1477, 2000.
The triangle.param method of Chessel (as coded in R package 'ade4')
Dray, S. and Dufour, A.B.(2007). The ade4 package: implementing the duality diagram for ecologists. Journal of Statistical, Software. 22(4): 1-20.
Chessel, D. and Dufour, A.B. and Thioulouse, J. (2004). The ade4 package - I - One-table methods. R News. 4: 5-10.
Dray, S. and Dufour, A.B. and Chessel, D. (2007). The ade4 package-II: Two-table and K-table methods. R News. 7(2): 47-52.
And the trilinear plot of Allen as reported by Zhu:
Zhu, M. (2008). How to draw a trilinear Plot. Statistical Computing & Graphics, 19(1), June, 2008.
In this version of the package tri-plot methods are used for the triABC2XY
and
triXY2ABC
transforms and a modification triangle.param
methods is used
to calculate suitable values for alim
, blim
and clim
.
As elsewhere, the use of lattice
is also gratefully acknowledged:
lattice: Sarkar, Deepayan (2008). Lattice: Multivariate Data Visualization with R. Springer, New York. ISBN 978-0-387-75968-5
## Example 1
## Basic triangle plot usage
trianglePlot(cadmium~copper+lead+zinc|lime,
data=lat.lon.meuse)
# Notes:
# Formula structure z ~ a0 + b0 + c0 |cond, where a0, b0 and
# c0 are the three axes of the triangle plot
# Data (and groups) assignment like in standard lattice plots.
# By default z is linked to col and cex.
# Unless overridden by user inputs or group or zcase setting.
# Plot handling is similar to loaPlot
# (So, see ?loaPlot and ?panelPal for further details.)
# Formula variations:
# basic triangle plot without z values assignment
# trianglePlot(~a0+b0+c0, ...)
# ... with z values set
# trianglePlot(z~a0+b0+c0, ...)
# ... with grouping
# trianglePlot(z~a0+b0+c0, groups=grps, ...)
## Example 2
## Basic frame (axes, grid, tick, annotation) management
trianglePlot(~1+1+1, type="n",
grid.alpha = 0.2,
ticks.alpha = 0.2) ## grid and tick alpha reset
# notes:
# Here, grid and ticks arguments are used to remove or modify these
# elements of the plot frame individually.
# Setting can be management in list form like in normal lattice or
# in a loa shorthand where e.g. the argument grid.a0.lty = 1 is equivalent
# to grid = list(a0 = list(lty = 1))
# (So, quicker if you are only changing a small number of elements.)
Run the code above in your browser using DataLab