## 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 scalesRun the code above in your browser using DataLab