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