[CHNOSZ-commits] r645 - in pkg/CHNOSZ: . demo inst vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Mar 1 13:16:54 CET 2021
Author: jedick
Date: 2021-03-01 13:16:54 +0100 (Mon, 01 Mar 2021)
New Revision: 645
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/demo/pourbaix.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/vignettes/anintro.Rmd
pkg/CHNOSZ/vignettes/vig.bib
Log:
Improve label appearance in demo/pourbaix.R
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2021-03-01 09:22:59 UTC (rev 644)
+++ pkg/CHNOSZ/DESCRIPTION 2021-03-01 12:16:54 UTC (rev 645)
@@ -1,6 +1,6 @@
Date: 2021-03-01
Package: CHNOSZ
-Version: 1.4.0-14
+Version: 1.4.0-15
Title: Thermodynamic Calculations and Diagrams for Geochemistry
Authors at R: c(
person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),
Modified: pkg/CHNOSZ/demo/pourbaix.R
===================================================================
--- pkg/CHNOSZ/demo/pourbaix.R 2021-03-01 09:22:59 UTC (rev 644)
+++ pkg/CHNOSZ/demo/pourbaix.R 2021-03-01 12:16:54 UTC (rev 645)
@@ -3,6 +3,8 @@
# After Pourbaix (1974, p. 312)
# 20210301 jmd first version
+library(CHNOSZ)
+
### PARAMETERS (to be changed by the user) ###
# Choose an element
@@ -15,12 +17,13 @@
# Set temperature and pressure
T <- 25
-P <- "Psat"
+# Can use "Psat" for T >= 100 degC
+P <- 1
# Set plot limits and resolution
pH <- c(-2, 16)
Eh <- c(-2, 2)
-res <- 400
+res <- 700
# Assign levels for equisolubility lines
levels <- seq(-6, 0, 2)
@@ -27,12 +30,16 @@
# Switches for using colors
color.fields <- TRUE
+color.water <- TRUE
color.lines <- TRUE
-color.water <- TRUE
+color.names <- TRUE
-# Adjustment for most aqueous species labels
-# (e.g. to get them out of the way of the upper water line in the Fe diagram)
-dy <- -0.2
+# Names of aqueous species to move down
+# (to avoid conflict with water lines or mineral names)
+namesdown <- c("MnOH+", "MnO", "Cu+2", "CuO")
+# Names of aqueous species to move down even more
+namesdown2 <- c("Fe+3", "FeOH+2", "FeO+", "HFeO2", "FeO2-",
+"HMnO2-", "MnO2-2")
### SCRIPT (can also be changed by the user if wanted!) ###
@@ -65,16 +72,11 @@
# from basis species as a function of Eh and pH
a_all <- affinity(pH = c(pH, res), Eh = c(Eh, res), T = T, P = P)
-# Create labels using chemical formulas instead of name of minerals
-names_all_a <- names_all_b <- info(a_all$species$ispecies)$formula
-
-# Plot diagram (LAYER 1: colors for all fields and labels for large-enough aqueous fields)
-# (it's better to label smaller aqueous fields relative to each other than to the minerals)
-names_all_a[a_all$species$state == "cr"] <- ""
+# Plot diagram (LAYER 1: colors for all fields)
limit.water <- fill <- NULL
if(!color.water) limit.water <- FALSE
if(!color.fields) fill <- NA
-d_all <- diagram(a_all, names = names_all_a, lty = 0, min.area = 0.1, limit.water = limit.water, fill = fill)
+d_all <- diagram(a_all, names = FALSE, lty = 0, min.area = 0.1, limit.water = limit.water, fill = fill)
# Calculate affinities for minerals
species(i_cr)
@@ -106,7 +108,7 @@
# Put this into the last-computed 'solubility' object
s$loga.balance <- smin
-# Plot diagram (LAYER 3: equisolubility lines)
+# Plot diagram (LAYER 2: equisolubility lines)
diagram(s, type = "loga.balance", levels = levels, contour.method = "flattest", add = TRUE, lwd = 1.7)
# Calculate affinities for aqueous species
@@ -114,18 +116,27 @@
species(i_aq, 0)
a_aq <- affinity(pH = c(pH, res), Eh = c(Eh, res), T = T, P = P)
-# Don't add existing labels
-d_all.ispecies_plotted <- d_all$species$ispecies[!is.na(d_all$namesx)]
-names_aq <- info(a_aq$species$ispecies)$formula
-names_aq[a_aq$species$ispecies %in% d_all.ispecies_plotted] <- ""
-
-# Plot diagram (LAYER 4: equal-activity lines and remaining labels for aqueous species)
+# Plot diagram (LAYER 3: equal-activity lines for aqueous species)
col <- ifelse(color.lines, 4, 1)
# Use a white base to improve contrast
# (so the line remains visible if it coincides with an equisolubility contour)
-diagram(a_aq, add = TRUE, col = "white", names = FALSE)
-diagram(a_aq, add = TRUE, lty = 2, col = col, names = names_aq, dy = dy)
+diagram(a_aq, add = TRUE, col = "white", lwd = 1.3, names = FALSE)
+# Plot diagram (LAYER 4: labels for aqueous species fields)
+# Apply y offset for specified names
+dy <- rep(0, nrow(a_aq$species))
+dy[a_aq$species$name %in% namesdown] <- -0.3
+dy[a_aq$species$name %in% namesdown2] <- -0.5
+# Use a white base for names
+rx <- diff(par("usr")[1:2])
+for(ddx in c(-rx/700, rx/700))
+ diagram(a_aq, add = TRUE, lty = 2, lwd = 0.6, col = col, dx = ddx, dy = dy, col.names = "white", bold = TRUE)
+ry <- diff(par("usr")[3:4])
+for(ddy in c(-ry/700, ry/700))
+ diagram(a_aq, add = TRUE, lty = 2, lwd = 0.6, col = col, dy = dy + ddy, col.names = "white", bold = TRUE)
+col.names <- ifelse(color.names, 4, 1)
+diagram(a_aq, add = TRUE, lty = 0, col = col, dy = dy, col.names = col.names)
+
# Add solids with unit activity
species(i_cr, 0)
# Add aqueous species with activity for last equisolubility line
@@ -144,5 +155,13 @@
# (this is the last layer, so names are above equal-activity lines,
# but we use positions calculated with the first equisolubility line
# so that names are within the shrunken parts of the mineral fields)
-names_all_b[a_all$species$state == "aq"] <- ""
-diagram(a_all, fill = NA, names = names_all_b, bold = TRUE, cex.names = 1.2, lty = 0, add = TRUE)
+# Create labels using chemical formulas instead of name of minerals
+formulas <- info(a_all$species$ispecies)$formula
+formulas[a_all$species$state == "aq"] <- ""
+diagram(a_all, fill = NA, names = formulas, bold = TRUE, cex.names = 1.2, lty = 0, add = TRUE)
+
+# Add title
+Texpr <- lT(T)
+Pexpr <- lP(P)
+main <- bquote(.(element)*"-O-H at "*.(Texpr)*" and "*.(Pexpr))
+title(main = main)
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2021-03-01 09:22:59 UTC (rev 644)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2021-03-01 12:16:54 UTC (rev 645)
@@ -32,8 +32,9 @@
\item Revise multi-metal.Rmd: Improve mineral abbreviations and placement
of labels; use updated DFT energies from Materials Project; add Mosaic
- Stacking 2 (minerals and aqueous species); add \emph{K}\S{eff} calculation
- (\href{https://doi.org/10.1016/j.gca.2021.01.038}{Robinson et al., 2021}).
+ Stacking 2 (minerals and aqueous species); add \emph{K}\S{eff}
+ calculation (\href{https://doi.org/10.1016/j.gca.2021.01.038}{Robinson et
+ al., 2021}); add Δ\emph{G}\s{pbx} color scale.
\item Restore \samp{lty.aq} and \samp{lty.cr} arguments to
\code{diagram()} to control plotting of aq-aq and cr-cr field boundaries.
Modified: pkg/CHNOSZ/vignettes/anintro.Rmd
===================================================================
--- pkg/CHNOSZ/vignettes/anintro.Rmd 2021-03-01 09:22:59 UTC (rev 644)
+++ pkg/CHNOSZ/vignettes/anintro.Rmd 2021-03-01 12:16:54 UTC (rev 645)
@@ -576,7 +576,7 @@
a <- affinity(pH = c(0, 12), Eh = c(-0.5, 1))
diagram(a, limit.water = TRUE)
```
-Let's use <span style="color:green">`diagram()`</span> to make a simple Pourbaix diagram for aqueous species in the system S-O-H.
+Let's use <span style="color:green">`diagram()`</span> to make a simple Eh-pH diagram for aqueous species in the system S-O-H.
After running the <span style="color:red">`basis()`</span> and <span style="color:red">`species()`</span> commands above, we can calculate the affinities on an Eh-pH grid.
With the default settings in <span style="color:green">`diagram()`</span>, areas beyond the stability limits of water are colored gray.
This can be changed by setting the `limit.water` argument to FALSE (to not show the stability region of water) or TRUE (to plot the main diagram only in the stable region of water).
@@ -596,6 +596,9 @@
```{r EhpH_plot_color, echo=TRUE, eval=FALSE}
```
+See the demos in the package for other examples of Eh-pH diagrams.
+In particular, [<span style="color:blue">`demo(pourbaix)`</span>](../demo) shows how to plot the concentrations of metals as equisolubility (or isosolubility) lines on Eh-pH diagrams [@Pou74].
+
Mineral stability diagrams often depict activity ratios, e.g. log (*a*<sub>Ca<sup>+2</sup></sub>/*a*<sub>H<sup>+</sup></sub><sup>2</sup>), on one or both axes.
The variables used for potential calculations in CHNOSZ include only a single chemical activity, e.g. log *a*<sub>Ca<sup>+2</sup></sub>.
However, you can set pH = 0 to generate diagrams that are geometrically equivalent to those calculated using activity ratios, and use <span style="color:green">`ratlab()`</span> to make the axes labels for the ratios.
@@ -615,10 +618,10 @@
retrieve("Mn", c("O", "H"), "cr")
```
-Below, these commands are used to identify the species in a Pourbaix diagram for the Mn-O-H system at 100 °C.
+Below, these commands are used to identify the species in an Eh-pH diagram for the Mn-O-H system at 100 °C.
This diagram includes Mn oxides (pyrolusite, bixbyite, hausmannite), Mn(OH)<sub>2</sub>, and aqueous Mn species.
-```{r retrieve_diagram, fig.margin=TRUE, fig.width=5, fig.height=5, dpi=dpi, out.width="100%", message=FALSE, results = "hide", cache=TRUE, fig.cap="Pourbaix diagram for the Mn-O-H system.", pngquant=pngquant, timeit=timeit}
+```{r retrieve_diagram, fig.margin=TRUE, fig.width=5, fig.height=5, dpi=dpi, out.width="100%", message=FALSE, results = "hide", cache=TRUE, fig.cap="Eh-pH diagram for the Mn-O-H system.", pngquant=pngquant, timeit=timeit}
# Set decimal logarithm of activity of aqueous species,
# temperature and plot resolution
logact <- -4
Modified: pkg/CHNOSZ/vignettes/vig.bib
===================================================================
--- pkg/CHNOSZ/vignettes/vig.bib 2021-03-01 09:22:59 UTC (rev 644)
+++ pkg/CHNOSZ/vignettes/vig.bib 2021-03-01 12:16:54 UTC (rev 645)
@@ -318,7 +318,7 @@
title = {{P}hase relations among silicates, copper iron sulfides, and aqueous solutions at magmatic temperatures},
year = {1985},
number = {7},
- pages = {1965 -- 1973},
+ pages = {1965--1973},
volume = {80},
doi = {10.2113/gsecongeo.80.7.1965},
}
@@ -933,3 +933,13 @@
volume = {in press},
doi = {10.1016/j.gca.2021.01.038},
}
+
+ at Book{Pou74,
+ author = {Pourbaix, M.},
+ publisher = {National Association of Corrosion Engineers and CEBELCOR},
+ title = {{A}tlas of {E}lectrochemical {E}quilibria in {A}queous {S}olutions},
+ year = {1974},
+ address = {Houston, Texas and Brussels},
+ edition = {2nd},
+ url = {https://www.worldcat.org/oclc/563921897},
+}
More information about the CHNOSZ-commits
mailing list