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)
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
User-resets for the axes, grid, tick and annotation
elements of the plots. These can be
Delimiters for a, b and c scales, equivalent to
A local argument, typically a list, that controls the
appearance of the a0/b0/c0 axes. This is roughly equivalent to the
Logicals. If a list or data.frame is supplied
Character. Handling method to be used if
trianglePlot generates a triangle plot using the lattice framework.
panel.trianglePlot... functions handle the appearance of triangle plot
panel.trianglePlot, which is assigned as the default
manages both the data layer of the plot and the plot frame (axes, grid, annotation,
axes and grid componets of the plot, and
a wrapper for these. The data layer, which by default is
can be accessed separately using the
triABC2XY converts supplied (a, b, c) coordinates to an (x, y) scale suitable
for use with
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
trianglePlot as well. Firstly, limits can be set individually with
clim, much like with
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
localScalesHandler to override normal
lattice handling of
scales. This allows parameters for axes other
'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
scales, and passing this on to the plot as the argument
panel.scales which can then be evaluated by an appropriate
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
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
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
lattice plot functions.
panel.trianglePlot... functions are intended for use
trianglePlot function call.
triABC2XY returns a list containing the named
y, which are the 2-D (x,y) transformations
of supplied (a,b,c)
triXY2ABC returns a list containing the named
c, which are the (a,b,c)
trianglePlot 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
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
c are lost when points are
plotted on these axes. So, the function
triXY2ABC returns the relative proportions
c, not the absolute amounts, when translating a 2-D
(x,y) coordinates into the associated (a, b, c) coordinates.
This is an in-development 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.
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.
trianglePlot scale adjustment options have been limited. Options under
evaluation include: (1) by
clim setting, equivalent to
ylim, (2) by
lims to set all axes ranges the same, and
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 inter-linked. The range of one axes
is a function of the other two axes ranges. So, setting these can generate contradictions.
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
a = b = c = c(0, 1). Suggestions on this topic are very welcome.
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
loa now use the most recent version of
This update should provide improved plot handling similar to recent versions of
GoogleMap functions which both already (from versions 0.2.0 onwards) use the latest
Code currently in revision. Please handle with care.
Code currently in revision. Please handle with care.
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
triXY2ABC transforms and a modification
triangle.param methods is used
to calculate suitable values for
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
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+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(~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.)