TernaryContour | R Documentation |
Draws contour lines to depict the value of a function in ternary space.
TernaryContour(
Func,
resolution = 96L,
direction = getOption("ternDirection", 1L),
region = getOption("ternRegion", ternRegionDefault),
within = NULL,
filled = FALSE,
legend,
legend... = list(),
nlevels = 10,
levels = pretty(zlim, nlevels),
zlim,
color.palette = function(n) hcl.colors(n, palette = "viridis", alpha = 0.6),
fill.col = color.palette(length(levels) - 1),
func... = list(),
...
)
Func |
Function taking vectors of coordinates |
resolution |
The number of triangles whose base should lie on the longest axis of the triangle. Higher numbers will result in smaller subdivisions and smoother colour gradients, but at a computational cost. |
direction |
(optional) Integer specifying the direction that the current ternary plot should point: 1, up; 2, right; 3, down; 4, left. |
region |
(optional) Named list of length two specifying the the
|
within |
List or matrix of x, y coordinates within which contours
should be evaluated, in any format supported by
|
filled |
Logical; if |
legend |
Character vector specifying annotations for colour scale.
If not provided, no colour legend is displayed.
Specify |
legend... |
List of additional parameters to send to
|
nlevels , levels , zlim , ... |
parameters to pass to
|
color.palette |
parameters to pass to
|
fill.col |
Sent as |
func... |
List of additional parameters to send to |
TernaryContour()
invisibly returns a list containing:
x
,y
: the Cartesian coordinates of each evaluated point;
z
: The value of Func()
at each coordinate.
Martin R. Smith (martin.smith@durham.ac.uk)
Other contour plotting functions:
ColourTernary()
,
TernaryDensityContour()
,
TernaryPointValues()
FunctionToContour <- function (a, b, c) {
a - c + (4 * a * b) + (27 * a * b * c)
}
# Set up plot
originalPar <- par(mar = rep(0, 4))
TernaryPlot(alab = "a", blab = "b", clab = "c")
values <- TernaryPointValues(FunctionToContour, resolution = 24L)
ColourTernary(
values,
legend = signif(seq(max(values), min(values), length.out = 4), 2),
bty = "n"
)
TernaryContour(FunctionToContour, resolution = 36L)
# Note that FunctionToContour is sent a vector.
# Instead of
BadMax <- function (a, b, c) {
max(a, b, c)
}
# Use
GoodMax <- function (a, b, c) {
pmax(a, b, c)
}
TernaryPlot(alab = "a", blab = "b", clab = "c")
ColourTernary(TernaryPointValues(GoodMax))
TernaryContour(GoodMax)
# Or, for a generalizable example,
GeneralMax <- function (a, b, c) {
apply(rbind(a, b, c), 2, max)
}
TernaryPlot(alab = "a", blab = "b", clab = "c")
# Fill the contour areas, rather than using tiles
TernaryContour(GeneralMax, filled = TRUE,
legend = c("Max", "...", "Min"), legend... = list(bty = "n"),
fill.col = hcl.colors(14, palette = "viridis", alpha = 0.6))
# Re-draw edges of plot triangle over fill
TernaryPolygon(diag(3))
# Restore plotting parameters
par(originalPar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.