Learn R Programming

loa (version 0.2.15)

1.3.trianglePlot: Triangle plots for lattice

Description

Triangle plot functions for lattice

Usage

trianglePlot(x, data = NULL, panel = panel.xyplot, 
          ref.grids = TRUE, ..., axes = TRUE, ticks = TRUE, 
          grids = TRUE, annotation = TRUE)

#associated panels
panel.triangleFrame(x = NULL, y = NULL, a = NULL, b = NULL, 
          c = NULL, ..., grids = grids, user.panel = panel.xyplot)
panel.triangleAxes(alim = NULL, blim = NULL, clim = NULL, ..., 
          panel.scales = panel.scales, axes = TRUE, 
          ticks = TRUE, annotation = TRUE)
panel.triangleGrids(a.grid = NULL, b.grid = NULL, c.grid = NULL, 
          ..., alim = NULL, blim = NULL, clim = NULL,  
          panel.scales = NULL, grids = 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)

Arguments

x
For trianglePlot, a formula with the general structure z ~ a + b + c | cond. The elements a, b and c, the inputs for the three axis on the triangle plot, are required, while z and conditioning co
data
(trianglePlot only) If supplied, the assumed source of the elements of formula x, typically a data.frame.
panel, user.panel
panel is the panel to use when plotting the data layer of trianglePlot outputs. By default this is the lattice function panel.xyplot. To handle the a/b/c to x/y conversion (and allow simil
ref.grids
Either a logical to turn off/on grid reference colors or a vector of colors to be applied to a, b and c axes, respectively. These are applied to the grid lines and axes tick and annotation components. Some users, particularly those less fam
...
Additional arguments. For trianglePlot, these are passed to associated data handlers (triABC2XY, cexHandler,
axes, ticks, grids, annotation
user resets for the axes, axis tick marks, grid lines axis annotation, respectively. These can be NULL or FALSE to turn off, TRUE to show, a vector (in which case they are assumed to be color assignments) o
y, a, b, c
(and x in relevant functions). a, b and c are the three scales of the triangle plot, and x and y are the equivalent 2-D projections.
panel.scales
A local argument, typically a list, that controls the appearance of the a/b/c axes. This is roughly equivalent to the scales argument used by conventional lattice plots to handle x and y axis, but intended for n
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.grid, b.grid, c.grid
If supplied the positions of the a, b and c grid lines, respectively.
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 'remove.row' replaces all enteries in the same row with NAs. (Note: this is different from na.omit
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
verbose
Logical, default FALSE. Should a full output be returned? The alternative FALSE generates a minimal report.

Value

  • trianglePlot returns trellis objects, much like conventional lattice plot functions. panel.triangle... functions are intended for use within a trianglePlot function call. With careful handling, they may also be used in conventional lattice plot calls. triABC2XY returns a list containing the named components x and y, which are the 2-D (x,y) equivalents 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 equivalents (x, y).

Details

trianglePlot generates a triangle plot using the lattice framework. panel.triangle... functions handle the appearance of triangle plot outputs. panel.triangleAxes and panel.triangleGrids generate a/b/c axes and grids, and panel.triangleFrame is a wrapper for these and the panel function supplied by the user. panel.triangleFrame also handles data scaling, so either (a, b, c) or appropriately rescaled (x, y) combinations can be supplied. triABC2XY converts supplied (a, b, c) coordinates to an (x, y) scale suitable for use with panel.triangleFrame, 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 a, b and c) 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.triangleAxes. 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, grids, annotation). As with localScalesHandler, the intention here is to provide more routine access to higher level plot control.

References

These function makes extensive use of code developed by others. Currently, several triangle plotting methods are under evaluation for use within this pacakge. 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. And as elsewhere, the use of lattice is 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 localScalesHandler and panel.localScale. In other packages: xyplot in lattice.

Examples

Run this code
## Example 1
## trianglePlot Examples

#  lat.lon.meuse plots

#  Cu/Pb/Zn triangle plot
trianglePlot(~copper+lead+zinc, data=lat.lon.meuse)   

#  ... with Cd as zcase 
#  (bubble plot, col and cex scaling)
trianglePlot(cadmium~copper+lead+zinc, data=lat.lon.meuse)

#  ... and conditioning by lime
trianglePlot(cadmium~copper+lead+zinc|lime, data=lat.lon.meuse)


##  Example 2
##  Local scales/axis control in trianglePlot

#  tri.frame - a 'standalone' function to demonstrate the
#  axes, ticks, grids, annotation handling in trianglePlot

tri.frame <- function(panel=panel.triangleGrids, axes = TRUE, ticks = TRUE, 
                      grids = TRUE, annotation = TRUE, ...){

    #default plot
    #blank canvas
    my.plot <- list(x=1~1, xlim=c(-0.2,1.1), ylim=c(-0.2,1.1), type = "n", 
                    xlab = "", ylab ="", panel = panel)

    #what you add
    extra.args <- list(...)

    #made local scale for a, b c axes
    #with localScalesHandler
    temp <- listUpdate(extra.args, list(allowed.scales = c("a", "b", "c"), 
                                        disallowed.scales = c("x", "y"), 
                                        remove.box = TRUE))
    extra.args <- listUpdate(extra.args, do.call(localScalesHandler, temp), 
                             ignore.a = "scales")

    #get sensible setting for axes, grids, ticks, annotation
    extra.args$axes <- getPlotArgs("axis.line", user.resets=axes, 
                                   elements = c("a", "b", "c"))
    extra.args$grids <- getPlotArgs("axis.line", user.resets=grids, 
                                    elements = c("a", "b", "c"))
    extra.args$ticks <- getPlotArgs("axis.line", user.resets=ticks, 
                                    elements = c("a", "b", "c"))
    extra.args$annotation <- getPlotArgs("axis.text", user.resets=annotation, 
                                    elements = c("a", "b", "c"))

    #update my.plot
    my.plot <- listUpdate(my.plot, extra.args)

    do.call(xyplot, my.plot)

}

#  You can send this any of the above panels
#  (works like x,y scales in lattice but for 
#  a,b,c scales of trianglePlot) 

tri.frame(panel.triangleGrids) #just the triangle plot grids
tri.frame(panel.triangleAxes)  #just the triangle plot axes
tri.frame(panel.triangleFrame)  #triangle plot 'frame' of both

tri.frame(panel.triangleAxes, axes = 1:3) #modify appearances
tri.frame(panel.triangleGrids, grids = list(a = list(lty=1, col = "green"),
                                            b = list(lty=2, col = "blue"),
                                            c = list(lty=3, col = "purple")))

tri.frame(panel.triangleFrame, scales = list(tick.number = 2)) #modify scales

Run the code above in your browser using DataLab