[CHNOSZ-commits] r334 - in pkg/CHNOSZ: . R demo inst man man/macros
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Oct 30 03:55:57 CET 2018
Author: jedick
Date: 2018-10-30 03:55:56 +0100 (Tue, 30 Oct 2018)
New Revision: 334
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/NAMESPACE
pkg/CHNOSZ/R/diagram.R
pkg/CHNOSZ/demo/affinity.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/diagram.Rd
pkg/CHNOSZ/man/macros/macros.Rd
Log:
diagram(): add 'lines' to output
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/DESCRIPTION 2018-10-30 02:55:56 UTC (rev 334)
@@ -1,6 +1,6 @@
-Date: 2018-10-11
+Date: 2018-10-30
Package: CHNOSZ
-Version: 1.1.3-41
+Version: 1.1.3-42
Title: Thermodynamic Calculations and Diagrams for Geo(bio)chemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/NAMESPACE 2018-10-30 02:55:56 UTC (rev 334)
@@ -65,7 +65,8 @@
# Imports from default packages
importFrom("grDevices", "dev.cur", "dev.off", "extendrange",
- "heat.colors", "png", "rainbow", "topo.colors", "dev.list")
+ "heat.colors", "png", "rainbow", "topo.colors", "dev.list",
+ "contourLines")
importFrom("graphics", "abline", "axTicks", "axis", "barplot", "box",
"contour", "image", "legend", "lines", "mtext", "par", "plot",
"plot.new", "plot.window", "points", "rect", "text", "title")
Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/R/diagram.R 2018-10-30 02:55:56 UTC (rev 334)
@@ -162,6 +162,7 @@
## identify predominant species
predominant <- NA
+ linesout <- NA
if(plotvar %in% c("loga.equil", "alpha", "A/(2.303RT)") & type!="saturation") {
pv <- plotvals
# some additional steps for affinity values, but not for equilibrated activities
@@ -469,7 +470,10 @@
}
# the categories (species/groups/etc) on the plot
zvals <- na.omit(unique(as.vector(predominant)))
- # take each possible pair
+ # initialize list to output line coordinates
+ linesout <- list()
+ iout <- 1
+ # take each possible pair of species
for(i in 1:(length(zvals)-1)) {
for(j in (i+1):length(zvals)) {
z <- predominant
@@ -478,9 +482,25 @@
# give them neighboring values (so we get one contour line)
z[z==zvals[i]] <- 0
z[z==zvals[j]] <- 1
- contour(xs, ys, z, levels=0.5, drawlabels=FALSE, add=TRUE, lty=lty, col=col, lwd=lwd)
+ # use contourLines() instead of contour() in order to get line coordinates 20181029
+ cLines <- contourLines(xs, ys, z, levels=0.5)
+ if(length(cLines) > 0) {
+ # loop in case contourLines returns multiple lines
+ for(k in 1:length(cLines)) {
+ # draw the lines
+ lines(cLines[[k]][2:3], lty=lty, col=col, lwd=lwd)
+ # keep the x and y values (list components 2 and 3)
+ linesout[[iout]] <- cLines[[k]][[2]]
+ names(linesout)[iout] <- paste0("x", k, "_", i, ".", j)
+ linesout[[iout+1]] <- cLines[[k]][[3]]
+ names(linesout)[iout+1] <- paste0("y", k, "_", i, ".", j)
+ iout <- iout + 2
+ }
+ }
}
}
+ # https://stackoverflow.com/questions/34570860/adding-na-to-make-all-list-elements-equal-length 20181029
+ lapply(linesout, `length<-`, max(lengths(linesout)))
}
## label plot function
# calculate coordinates for field labels
@@ -577,7 +597,7 @@
# font metric state and subsequent errors adding e.g. subscripted text to plot)
if(length(na.omit(unique(as.vector(zs)))) > 1) {
if(!is.null(dotted)) plot.line(zs, xlim, ylim, dotted, col, lwd, xrange=xrange)
- else contour.lines(predominant, xlim, ylim, lty=lty, col=col, lwd=lwd)
+ else linesout <- contour.lines(predominant, xlim, ylim, lty=lty, col=col, lwd=lwd)
}
# re-draw the tick marks and axis lines in case the fill obscured them
if(tplot & !identical(fill, "transparent")) thermo.axis()
@@ -585,8 +605,9 @@
out2D <- list(namesx=pn$namesx, namesy=pn$namesy, inames=pn$inames)
} # end if(nd==2)
} # end if(plot.it)
-
- out <- c(eout, list(plotvar=plotvar, plotvals=plotvals, names=names, predominant=predominant), out2D)
+ out <- c(eout, list(plotvar=plotvar, plotvals=plotvals, names=names, predominant=predominant))
+ if(!identical(predominant, NA) & is.null(dotted)) out <- c(out, list(lines=linesout))
+ out <- c(out, out2D)
return(invisible(out))
}
Modified: pkg/CHNOSZ/demo/affinity.R
===================================================================
--- pkg/CHNOSZ/demo/affinity.R 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/demo/affinity.R 2018-10-30 02:55:56 UTC (rev 334)
@@ -77,7 +77,7 @@
# make a plot; set units to get correct label
E.units("J")
plot(out$Z.C, out$G.18, pch=20, xlim=c(-1.1, 1.1), ylim=c(-200, 500),
- xlab=axis.label("ZC"), ylab=axis.label("DGr"))
+ xlab=axis.label("ZC"), ylab=axis.label("DGr", prefix="k"))
points(out$Z.C, out$G.100, col="red", pch=20)
legend("topleft", pch=c(20, 20), col=c("black", "red"),
legend=describe.property(c("T", "T"), c(18, 100)))
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/inst/NEWS 2018-10-30 02:55:56 UTC (rev 334)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-41 (2018-10-11)
+CHANGES IN CHNOSZ 1.1.3-42 (2018-10-30)
---------------------------------------
THERMODYNAMIC DATA
@@ -75,6 +75,10 @@
formatted names (e.g. chemical formulas), and 'font' applies to those
without formatting.
+- 'lines' is added to the return list of diagram(), giving the
+ coordinates of lines (field boundaries) on 2-D diagrams (these are
+ taken from the output of contourLines()).
+
BUG FIXES
- Fix a bug where subcrt()$reaction$coeffs was incorrect for reactions
Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/man/diagram.Rd 2018-10-30 02:55:56 UTC (rev 334)
@@ -139,7 +139,7 @@
\code{fill.NA} is also used to specify the color outside the water stability limits on Eh-pH or pe-pH diagrams, when \code{limit.water} is TRUE.
Note that the default for \code{fill.NA} is automatically changed to \samp{transparent} when \code{add} is TRUE.
-The default line-drawing algorithm uses \code{\link{contour}} to draw smooth-looking diagonal and curved lines, at the expense of not coinciding exactly with the rectangular grid (which is still used for drawing colors).
+The default line-drawing algorithm uses \code{\link{contourLines}} to obtain smooth-looking diagonal and curved lines, at the expense of not coinciding exactly with the rectangular grid that is used for drawing colors.
\code{lty}, \code{col}, and \code{lwd} can be specified, but limiting the lines via \code{xrange} is not currently supported.
To go back to the old behavior for drawing lines, set \code{dotted} to \samp{0}.
The old behavior does not follow \code{lty}; instead, the style of the boundary lines on 2-D diagrams can be altered by supplying one or more non-zero integers in \code{dotted}, which indicates the fraction of line segments to omit; a value of \samp{1} or NULL for \code{dotted} has the effect of not drawing the boundary lines.
@@ -159,7 +159,7 @@
If \code{type} is \samp{saturation}, the function plots the line for each species where the affinity of formation equals zero.
If for a given species no saturation line is possible or the range of the diagram is beyond the saturation line, the function prints a message instead.
If \code{type} is the name of a basis species, the equilibrium activity of the selected basis species in each of the formation reactions is plotted.
-In the case of 2-D diagrams, both of these options use \code{\link{contour}} to draw the lines (see the \CO2-acetic acid example in \code{\link{buffer}}.
+In the case of 2-D diagrams, both of these options use \code{\link{contour}} to draw the lines (see the \CO2-acetic acid example in \code{\link{buffer}}).
The \samp{saturation} diagram can handle multiple species, but if \code{type} is the name a basis species, then only the first species of interest is used in the calculation, and a warning is produced if there is more than one.
}
@@ -183,9 +183,13 @@
This argument has the same format as \code{ispecies}, and can be used e.g. to display the relative numbers of species for comparison with the stability calculations.
}
-\value{
-For speciation diagrams (1-D), an \code{\link{invisible}} list of the chemical activities of the species, or their degrees of formation (if \code{alpha} is \code{TRUE}), at each point.
-For predominance diagrams (2-D), an invisible list with elements \code{species}, the dataframe describing the species, \code{out}, which species predominates at each grid point, and \code{A}, a list of the calculated values of the chemical affinity (per balanced quantity) (log10 dimensionless) at each point.
+\section{Value}{
+ The function returns an \code{\link{invisible}} list containing, first, the contents of \code{eout}, i.e. the provided output of \code{\link{affinity}} or \code{\link{equilibrate}}.
+ To this are added the name of the plotted variable in \code{plotvar}, the plotted values in \code{plotvals}, and the names used for labeling the plot in \code{names}.
+ For 1-D diagrams, \code{plotvals} usually corresponds to the chemical activities of the species (i.e. \code{eout$loga.equil}), or, if \code{alpha} is \code{TRUE}, their mole fractions (degrees of formation).
+ For 2-D diagrams, the output also contains \code{predominant}, giving the numbers (from the \code{\link{species}} definition) of the predominant (aka maximum-affinity) species at each grid point.
+ The rows and columns of \code{predominant} correspond to the x- and y-variables, respectively.
+ Finally, the output for 2-D diagrams contains a \code{lines} component, giving the x- and y-coordinates of the field boundaries computed using \code{\link{contourLines}}; the values are padded to equal length with NAs to faciliate exporting the results using \code{\link{write.csv}}.
}
\seealso{
@@ -293,7 +297,7 @@
LaRowe, D. E. and Helgeson, H. C. (2007) Quantifying the energetics of metabolic reactions in diverse biogeochemical systems: electron flow and ATP synthesis. \emph{Geobiology} \bold{5}, 153--168. \url{https://doi.org/10.1111/j.1472-4669.2007.00099.x}
- Majzlan, J., Navrotsky, A., McClesky, R. B. and Alpers, C. N. (2006) Thermodynamic properties and crystal structure refinement of ferricopiapite, coquimbite, rhomboclase, and Fe2(SO4)3(H2O)5. \emph{Eur. J. Mineral.} \bold{18}, 175--186. \url{https://doi.org/10.1127/0935-1221/2006/0018-0175}
+ Majzlan, J., Navrotsky, A., McClesky, R. B. and Alpers, C. N. (2006) Thermodynamic properties and crystal structure refinement of ferricopiapite, coquimbite, rhomboclase, and Fe\s{2}(SO\s{4})\s{3}(H\s{2}O)\s{5}. \emph{Eur. J. Mineral.} \bold{18}, 175--186. \url{https://doi.org/10.1127/0935-1221/2006/0018-0175}
}
\concept{Main workflow}
Modified: pkg/CHNOSZ/man/macros/macros.Rd
===================================================================
--- pkg/CHNOSZ/man/macros/macros.Rd 2018-10-12 13:02:43 UTC (rev 333)
+++ pkg/CHNOSZ/man/macros/macros.Rd 2018-10-30 02:55:56 UTC (rev 334)
@@ -17,6 +17,7 @@
\newcommand{\s2}{\ifelse{latex}{\eqn{_2}}{\ifelse{html}{\out{<sub>2</sub>}}{2}}}
\newcommand{\s3}{\ifelse{latex}{\eqn{_3}}{\ifelse{html}{\out{<sub>3</sub>}}{3}}}
\newcommand{\s4}{\ifelse{latex}{\eqn{_4}}{\ifelse{html}{\out{<sub>4</sub>}}{4}}}
+\newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
% superscript numbers
\newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
More information about the CHNOSZ-commits
mailing list