util.plot: Utility functions for plots

util.plotR Documentation

Utility functions for plots

Description

Label plots and figures, generate labels for axes and subplots, add stability lines for water, or get colors for a set of numeric values.

Usage

  label.plot(label, xfrac = 0.07, yfrac = 0.93, paren = FALSE,
    italic = FALSE, ...)
  usrfig()
  label.figure(label, xfrac = 0.05, yfrac = 0.95, paren = FALSE,
    italic = FALSE, ...)
  water.lines(eout, which = c("oxidation","reduction"),
    lty = 2, lwd = 1, col = par("fg"), plot.it = TRUE)
  mtitle(main, line = 0, spacing = 1, ...)
  ZC.col(z)
  hyphen.in.pdf(x)

Arguments

label

character, label to place on plot

xfrac

numeric, fractional location on x-axis for placement of label

yfrac

numeric, fractional location on y-axis for placement of label

paren

logical, add parentheses around label text?

...

further arguments passed to text or mtext

italic

logical, italicize label text?

eout

data frame, output of affinity, equilibrate, or diagram

which

character, which of oxidation/reduction lines to plot

lty

numeric, line type

lwd

numeric, line width

col

character, color

plot.it

logical, plot the lines?

main

character, text for plot title

line

numeric, margin line on which to place plot title

spacing

numeric, spacing between multiple lines

z

numeric, set of values

x

character, any text object

Details

water.lines plots lines representing the oxidation and reduction stability limits of water on Eh/pe/\logfO2/\logfH2 vs pH/\T/\P diagrams. The x- and y-variables and their ranges are taken from eout. Values of \T, \P, pH, and \logaH2O, not corresponding to either axis, are also taken from eout. which controls which lines are drawn (‘⁠oxidation⁠’, ‘⁠reduction⁠’, or both (the default)). The value of swapped in the output reflects whether pH, \T, or \P is on the x-axis (TRUE) or y-axis (FALSE). NA is returned for any diagram for variables that can not be processed (including diagrams with more than 2 variables).

label.plot and label.figure add identifying text within the plot region and figure region. The value given for label is used, optionally italicized and with parentheses (like (a)). The location of the label is controlled by xfrac and yfrac (the fractional coordinates of either the plot or figure region), and ... can include other parameters such as cex and adj that are passed to text.

usrfig returns the limits of the figure region in “user” coordinates (i.e. the limits of the plot region, from par("usr")). It is a supporting function for label.figure but is also useful for other circumstances where information must be added at a particular location in a figure.

mtitle can be used to add a multi-line title to a plot. It loops over each element of main and places it on a separate margin line using mtext. The spacing of the last (bottom) line from the edge of the plot is specified by line. This function exists to facilitate using expressions in multiline titles.

ZC.col uses colorspace to generate colors from a diverging palette (red - light grey - blue) corresponding to the values in z. Red is associated with lower values of z. This function is intended to generate colors for distinguishing average oxidation state of carbon ZC, but any numeric values can be supplied.

If a PDF device is active, hyphen.in.pdf replaces all instances of ASCII hyphen (⁠-⁠) in x with the Unicode hyphen (⁠\uad⁠). This is done so that hyphens don't get displayed as minus signs in R graphics output, but it only works for the PDF device.

Examples

basis(c("H2S", "H2O", "H+", "e-"))
species(c("H2S", "HS-", "S3-", "SO2", "HSO4-", "SO4-2"))
a <- affinity(pH = c(0, 12), Eh = c(-1, 1), T = 200)
opar <- par(mfrow = c(2, 2))
diagram(a, grid = "both")
title(main = 'diagram(a, grid = "both")')
diagram(a, grid = "major")
title(main = 'diagram(a, grid = "major")')
diagram(a, grid = "minor")
title(main = 'diagram(a, grid = "minor")')
diagram(a, fill = "terrain")
thermo.axis(grid = "major", col.grid = "slategray")
title(main = 'thermo.axis(grid = "major")')
par(thermo()$opar)
par(opar)

CHNOSZ documentation built on Jan. 16, 2026, 3:01 a.m.