1.3.trianglePlot: Triangle plots

Description Usage Arguments Details Value Note Author(s) References See Also Examples


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)  

   #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)



For trianglePlot only, a formula with the general 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).

y, a, a0, b, b0, c, c0

(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.

loa.settings, plot, process

loaPlot arguments used to manage panelPal activity.

grid, axes, ticks, annotation

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 or grids = list(col = 2) make all axes red, while calls including grid.a0.col = 2 or grid = list(a0 = list(col = 2) only recolor the first (a0) axis.

alim, blim, clim

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).

force.abc, force.xy

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 '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.


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 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.


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) 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 trianglePlot.



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 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.

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 inter-linked. 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.


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.


Code currently in revision. Please handle with care.


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 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

See Also

In loa: For in-panel axis/scale generation, see loaPlot, panelPal, localScalesHandler and panel.localScale.

In other packages: xyplot in lattice.


## Example 1
## Basic triangle plot usage


# 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.)

loa documentation built on July 4, 2017, 3:01 p.m.

Search within the loa package
Search all R packages, documentation and source code