1.3.trianglePlot {loa}R Documentation

Triangle plots

Description

Triangle plot functions for Lattice.

Usage


   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)

Arguments

x

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

data

For trianglePlot only, if supplied, the assumed source of the elements of formula x, typically a data.frame.

...

Additional arguments.

ref.cols

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

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

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 make all axes red, while calls including grid.a0.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.

panel.scales

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.

if.na

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.

if.neg

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.

verbose

Logical, default FALSE. Should a full output be returned? The alternative FALSE generates a minimal report.

ans

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.

n

For triABCSquareGrid only, number of points to divide each axes by when generating the data grid.

Details

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.

Value

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.

Note

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 2-D (x,y) coordinates into the associated (a, b, c) coordinates.

Development:

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.

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, triABCSquareGrid:

Code currently in revision. Please handle with care.

Author(s)

Karl Ropkins

References

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.

Examples


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

[Package loa version 0.2.48.3 Index]