Triangle plot functions for Lattice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22  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)
#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)

x 
For 
data 
For 
... 
Additional arguments. 
ref.cols 
Either a logical to turn off/on grid colorcoding 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

y, a, a0, b, b0, c, c0 
(and 
loa.settings, plot, process 

grid, axes, ticks, annotation 
Userresets for the axes, grid, tick and annotation
elements of the plots. These can be 
alim, blim, clim 
Delimiters for a, b and c scales, equivalent to 
panel.scales 
A local argument, typically a list, that controls the
appearance of the a0/b0/c0 axes. This is roughly equivalent to the 
force.abc, force.xy 
Logicals. If a list or data.frame is supplied
to 
if.na 
Character. Handling method to be used if 
if.neg 
Character. Like 
verbose 
Logical, default 
ans 
For 
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.
triABC2XY
converts supplied (a, b, c) coordinates to an (x, y) scale suitable
for use with panel.trianglePlotFrame
, etc.
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
and triXY2ABC
,
and therefore trianglePlot
as well. 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
cutoffs 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 twofold.
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 nonstandard 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.
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 2D (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)
trianglePlot
coordinates associated with supplied 2D (x, y) that
trianglePlot
would generate.
resetTriLims
returns a supplied trellis object, rescaled
based on the assumption that it is a trianglePlot
.
General:
With triangle plots, the (a0, b0, c0) scales are proportional. So regardless of the
absolute sizes of a coordinate set (a,b,c), values are plotted and handled
as proportions, i.e. a/(a+b+c), b/(a+b+c) and c/(a+b+c), respectively. This means
that absolute values of a
, b
and c
are lost when points are
plotted on these axes. So, the function triXY2ABC
returns the relative proportions
of a
, b
and c
, not the absolute amounts, when translating a 2D
(x,y) coordinates into the associated (a, b, c) coordinates.
Development:
This is an indevelopment plot, and 'best handling' strategies have not been decided for several elements. So, future versions of these functions may differ significantly from the current version.
In particular:
Current axes assignments, e.g. (a, b, c) versus (a0, b0, c0), etc., have not be finalised. So, these may change in future versions of the function.
Currently, trianglePlot
scale adjustment options have been limited. Options under
evaluation include: (1) by alim
, blim
, clim
setting, equivalent to
xlim
and ylim
, (2) by lims
to set all axes ranges the same, and
(3) by maxs
to setting all axes range maximums and mins
to set all axes
range minimums, etc.
These options are currently only avialable via the data converters.
One of the issues here is that the axes ranges are all interlinked. The range of one axes
is a function of the other two axes ranges. So, setting these can generate contradictions.
For example, lims=c(0,0.1)
should in theory set all ranges to (0, 0.1). But, the triangle
a = b = c = c(0, 0.1)
cannot exist. Therefore, the plot would attempt to recover
the extended range that includes all the requested ranges (a = c(0, 0.1)
,
b = c(0, 0.1)
and c = c(0, 0.1)
), which in this case is the full
range: a = b = c = c(0, 1)
. Suggestions on this topic are very welcome.
trianglePlot
:
As part of the loa
version 0.2.19 update, trianglePlot
was rewritten to run
with the most recent version of panelPal
function. This means all plot
functions in loa
now use the most recent version of panelPal
.
This update should provide improved plot handling similar to recent versions of loaPlot
and GoogleMap
functions which both already (from versions 0.2.0 onwards) use the latest
version of panelPal
.
panel.trianglePlotAxes
:
Code currently in revision. Please handle with care.
triABC2XY
:
Code currently in revision. Please handle with care.
Karl Ropkins
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 triplot 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, 14731477, 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): 120.
Chessel, D. and Dufour, A.B. and Thioulouse, J. (2004). The ade4 package  I  Onetable methods. R News. 4: 510.
Dray, S. and Dufour, A.B. and Chessel, D. (2007). The ade4 packageII: Twotable and Ktable methods. R News. 7(2): 4752.
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 triplot 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 9780387759685
In loa
: For inpanel axis/scale generation, see loaPlot
, panelPal
,
localScalesHandler
and panel.localScale
.
In other packages: xyplot
in lattice
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51  ## Example 1
## Basic triangle plot usage
trianglePlot(cadmium~copper+lead+zinclime,
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(~copper+lead+zinc, data=lat.lon.meuse)
# ... with z values set
# trianglePlot(cadmium~copper+lead+zinc, data=lat.lon.meuse)
# ... with grouping
# trianglePlot(cadmium~copper+lead+zinc, groups = lat.lon.meuse$lime,
# data=lat.lon.meuse)
## Example 2
## Basic frame (axes, grid, tick, annotation) management
# trianglePlot(~1+1+1, type="n") ## empty frame
## make using type="n"
# trianglePlot(~1+1+1, type="n",
# grid = FALSE) ## turn off grid
# trianglePlot(~1+1+1, type="n",
# grid.col = 2) ## or change plot settings
# trianglePlot(~1+1+1, type="n",
# grid.a0.lty = 1)
# trianglePlot(~1+1+1, type="n",
# grid = list(a0 = list(lty = 1)))
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.)

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.
Please suggest features or report bugs with the GitHub issue tracker.
All documentation is copyright its authors; we didn't write any of that.