Learn R Programming

CHNOSZ (version 0.9-7)

util.plot: Functions to Create and Modify Plots

Description

Initialize a new plot window using preset parameters, open a postcript file for plotting, add an axis or title to a plot, generate labels for plot axes and for identification of subplots and physical and chemical conditions, add stability lines for water to a diagram.

Usage

thermo.plot.new(xlim, ylim, xlab, ylab, cex = par("cex"),
    mar = NULL, lwd = par("lwd"), side = c(1,2,3,4), 
    mgp = c(1.2, 0.3, 0), cex.axis = par("cex"), col = par("col"),
    yline = NULL, axs = "i", do.box = TRUE, ticks = NULL, las = 1,
    xline = NULL)
  thermo.postscript(file, family = "Helvetica", width = 8, 
    height = 6, horizontal = FALSE)
  thermo.axis(lab = "x-axis", side = 1, line = 1.5, cex = par("cex"),
    lwd = par("lwd"), T = NULL, col = par("col"))
  label.plot(x, xfrac = 0.95, yfrac = 0.9, cex = 1, paren = TRUE, 
    adj = 1)
  axis.label(lab, opt = NULL, do.state = TRUE, oldstyle = FALSE,
    do.upper = FALSE, mol = "mol", state = NULL, as.expression = TRUE)
  species.label(formula, do.state = FALSE, state = "", do.log = FALSE,
    as.expression = TRUE)
  water.lines(xaxis = "pH", yaxis = "Eh", T = 298.15, P = "Psat", 
    which = c("oxidation","reduction"), logaH2O = 0, lty = 2, 
    col = par("fg"), xpoints = NULL)
  mtitle(main, ...)
  residualsplot(residuals, property = "Cp", model = "big")

Arguments

xlim
numeric, limits of the $x$-axis.
ylim
numeric, limits of the $y$-axis.
xlab
character, $x$-axis label.
ylab
character, $y$-axis label.
cex
numeric, character expansion factor for labels.
mar
numeric, width (number of lines) of margins on each side of plot.
lwd
numeric, line width.
side
numeric, which sides of plot to draw axes.
mgp
numeric, sizes of margins of plot.
cex.axis
numeric, character expansion factor for names of axes.
col
character, line color.
yline
numeric, margin line on which to plot $y$-axis name.
axs
character, setting for axis limit calculation.
do.box
logical, draw a box around the plot?
ticks
numeric, same effect as side (retained for backwards compatibility).
las
numeric, style for axis labels
xline
numeric, margin line on which to plot $x$-axis name.
file
character, path to a file.
family
character, font family.
width
numeric, width of plot.
height
numeric, height of plot.
horizontal
logical, create plot in landscape mode?
lab
character, description of axis label.
line
numeric, margin line to plot axis label.
T
numeric, temperature (K).
x
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?
adj
numeric, parameter for text alignment.
opt
character or numeric, options for axis labels.
do.state
logical, append state abbreviation to label?
oldstyle
logical, use old style of axis labels?
do.upper
logical, use uppercase letters in axis label?
mol
character, string to use as the denominator of units in axis label.
formula
character, representation of chemical formula.
state
character, designation of physical state.
as.expression
logical, make the return value an expression?
do.log
logical, prepend a text indicating logarithm of activity or fugacity?
xaxis
character, description of $x$-axis.
yaxis
character, description of $y$-axis.
P
numeric, pressure (bar).
which
character, which of oxidation/reduction lines to plot.
logaH2O
numeric, logarithm of the activity of $\mathrm{H_2O}$.
lty
numeric, line type.
xpoints
numeric, points to plot on $x$ axis.
main
character, text for plot title.
...
further arguments passed to mtext.
residuals
numeric, named vector of residuals to plot.
property
character, name of property.
model
character, name of model to use in plot title.

Side Effects

These functions create or modify a plot.

Details

thermo.postscript calls postscript with some custom parameters used by the package author (and might be handy for other users of the package as well).

thermo.plot.new sets parameters for a new plot, creates a new plot using plot.new, and adds axes and major and minor ticks to the plot. Plot parameters (see par) including cex, mar, lwd, mgp and axs can be given, as well as a numeric vector in ticks identifying which sides of the plot receive tick marks. yline, if present, denotes the margin line (default par('mgp')[1]) where the y-axis name is plotted.

axis.label returns an expression to be used for plotting an axis label, which may be the symbol for a thermodynamic properties, chemical activity or fugacity, or one of T, P, Eh, pH, pe or logK. If as.expression is FALSE, the quoted text of the label is returned instead. An expression for chemical activity or fugacity is returned if the first argument is the name of one of the basis species (e.g., O2). The expression in this case includes italic and subscripted symbols, unless oldstyle is TRUE, when labels with a simpler format (e.g. O2 (log f)) are returned. The default value of NULL of opt means to use the state this basis species is in, or if this basis species is not present to use the value in thermo$opt$state. Likewise, if x is T or P the units of temperature or pressure are determined using nuts (which also refers to thermo$opt). do.upper, if TRUE, tells the function to print the label using uppercase letters. Labels for properties can be generated by using e.g. DGf or DG0r as arguments. mol (default: mol) refers to the denominator of the units (default: molality); this can be changed to represent e.g. specific units, by setting mol to g. opt when generating labels for properties indicates the prefix to place on the units.

species.label is like axis.label but is specifically intended for generating expressions for the chemical formulas of species. The state (in parentheses) is included in the expression only if state is not NULL. If do.log is TRUE, the expression will contain a prefix in front of the formula that indicates chemical activity (like log_a or log_f).

water.lines plots lines representing the oxidation and reduction stability limits of water on yaxis-xaxis diagrams, where yaxis can be Eh or O2, and xaxis can be pH or T. which controls which lines (oxidation, reduction, or both (the default)) are drawn, logaH2O (default 0) denotes the logarithm of the activity of water, lty (default 2) the line type, col (default par('fg'), the foreground color), and xpoints an optional list of points on the x axis to which to restrict the plotting (default of NULL refers to the axis limits).

label.plot adds identifying text to the plot; the value given for x is made into a label like $(a)$. The location of the label is controlled by xfrac and yfrac (the fractional locations along the respective axes) as well as adj (the text alignment parameter, see text).

thermo.axis is used to add axes and axis labels to plots, with some default style settings (rotation of numeric labels) and conversions between oxidation-reduction scales (called by thermo.plot.new). It also adds minor tick marks.

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. This function exists to facilitate using expressions in multiline titles (see revisit for an example.)

residualsplot produces a barchart with options useful for plotting residuals of group contribution models for thermodynamic properties. It plots horizontal bars stacked with largest on top. The names of the residuals argument (i.e., the names of model species) are plotted across from each respective bar. The axis title is taken from the property (probably Cp or V), and the plot title includes the model name. See the xadditivity vignette for examples of these plots.