[CHNOSZ-commits] r442 - in pkg/CHNOSZ: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 15 08:46:08 CEST 2019


Author: jedick
Date: 2019-04-15 08:46:07 +0200 (Mon, 15 Apr 2019)
New Revision: 442

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/examples.R
   pkg/CHNOSZ/R/util.plot.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/util.plot.Rd
Log:
thermo.axis(): add 'grid' argument (also usable in diagram())


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2019-04-15 04:26:29 UTC (rev 441)
+++ pkg/CHNOSZ/DESCRIPTION	2019-04-15 06:46:07 UTC (rev 442)
@@ -1,6 +1,6 @@
 Date: 2019-04-15
 Package: CHNOSZ
-Version: 1.3.1-22
+Version: 1.3.1-23
 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/R/examples.R
===================================================================
--- pkg/CHNOSZ/R/examples.R	2019-04-15 04:26:29 UTC (rev 441)
+++ pkg/CHNOSZ/R/examples.R	2019-04-15 06:46:07 UTC (rev 442)
@@ -6,7 +6,7 @@
   # run all the examples in CHNOSZ documentation
   .ptime <- proc.time()
   topics <- c("thermo", "examples",
-    "util.array", "util.blast", "util.data", "util.expression",
+    "util.array", "util.blast", "util.data", "util.expression", "util.plot",
     "util.fasta", "util.formula", "util.matrix", "util.misc", "util.seq", "util.units",
     "util.water", "taxonomy", "info", "retrieve", "add.obigt", "protein.info",
     "hkf", "water", "IAPWS95", "subcrt", "berman",

Modified: pkg/CHNOSZ/R/util.plot.R
===================================================================
--- pkg/CHNOSZ/R/util.plot.R	2019-04-15 04:26:29 UTC (rev 441)
+++ pkg/CHNOSZ/R/util.plot.R	2019-04-15 06:46:07 UTC (rev 442)
@@ -3,7 +3,7 @@
 
 thermo.plot.new <- function(xlim,ylim,xlab,ylab,cex=par('cex'),mar=NULL,lwd=par('lwd'),side=c(1,2,3,4),
   mgp=c(1.7,0.3,0),cex.axis=par('cex'),col=par('col'),yline=NULL,axs='i',do.box=TRUE,
-  las=1,xline=NULL, ...) {
+  las=1,xline=NULL, grid = "", col.grid = "gray", ...) {
   # start a new plot with some customized settings
   thermo <- get("thermo", CHNOSZ)
   # 20120523 store the old par in thermo$opar
@@ -31,8 +31,8 @@
   if(is.null(yline)) yline <- mgp[1]
   thermo.axis(ylab,side=2,line=yline,cex=cex.axis,lwd=NULL)
   # (optional) tick marks
-  if(1 %in% side) thermo.axis(NULL,side=1,lwd=lwd)
-  if(2 %in% side) thermo.axis(NULL,side=2,lwd=lwd)
+  if(1 %in% side) thermo.axis(NULL,side=1,lwd=lwd, grid = grid, col.grid = col.grid)
+  if(2 %in% side) thermo.axis(NULL,side=2,lwd=lwd, grid = grid, col.grid = col.grid)
   if(3 %in% side) thermo.axis(NULL,side=3,lwd=lwd)
   if(4 %in% side) thermo.axis(NULL,side=4,lwd=lwd)
 }
@@ -198,13 +198,19 @@
 #   with some default style settings (rotation of numeric labels)
 # With the default arguments (no labels specified), it plots only the axis lines and tick marks
 #   (used by diagram() for overplotting the axis on diagrams filled with colors).
-thermo.axis <- function(lab=NULL,side=1:4,line=1.5,cex=par('cex'),lwd=par('lwd'),col=par('col')) {
+thermo.axis <- function(lab=NULL,side=1:4,line=1.5,cex=par('cex'),lwd=par('lwd'),col=par('col'), grid = "", col.grid="gray") {
   if(!is.null(lwd)) {
-    ## plot major tick marks and numeric labels
     for(thisside in side) {
+
+      ## get the positions of major tick marks and make grid lines
+      at <- axis(thisside,labels=FALSE,tick=TRUE) 
+      if(grid %in% c("major", "both") & thisside==1) abline(v = at, col=col.grid)
+      if(grid %in% c("major", "both") & thisside==2) abline(h = at, col=col.grid)
+      ## plot major tick marks and numeric labels
       do.label <- TRUE
       if(missing(side) | (missing(cex) & thisside %in% c(3,4))) do.label <- FALSE
       at <- axis(thisside,labels=do.label,tick=TRUE,lwd=lwd,col=col,col.axis=col) 
+
       ## plot minor tick marks
       # the distance between major tick marks
       da <- abs(diff(at[1:2]))
@@ -242,6 +248,9 @@
       daxt <- (axt - myusr[1])/di
       daxt <- (daxt-round(daxt))*di
       at <- at + daxt
+      ## get the positions of major tick marks and make grid lines
+      if(grid %in% c("minor", "both") & thisside==1) abline(v = at, col=col.grid, lty = 3)
+      if(grid %in% c("minor", "both") & thisside==2) abline(h = at, col=col.grid, lty = 3)
       tcl <- par('tcl') * 0.5
       axis(thisside,labels=FALSE,tick=TRUE,lwd=lwd,col=col,col.axis=col,at=at,tcl=tcl)
     }

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2019-04-15 04:26:29 UTC (rev 441)
+++ pkg/CHNOSZ/inst/NEWS	2019-04-15 06:46:07 UTC (rev 442)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.3.1-22 (2019-04-15)
+CHANGES IN CHNOSZ 1.3.1-23 (2019-04-15)
 ---------------------------------------
 
 - Add thermo/stoich.csv.xz (loaded as thermo()$stoich), containing a
@@ -34,6 +34,10 @@
 - In the output of affinity(), the list of 'vals' (the values of the
   input variables) now has names corresponding to the variables.
 
+- In diagram(), a background grid corresponding to major and/or minor
+  tick marks can be added using the 'grid' argument. Or, use
+  thermo.axis() after diagram() to overlay a grid.
+
 CHANGES IN CHNOSZ 1.3.1 (2019-03-02)
 ------------------------------------
 

Modified: pkg/CHNOSZ/man/util.plot.Rd
===================================================================
--- pkg/CHNOSZ/man/util.plot.Rd	2019-04-15 04:26:29 UTC (rev 441)
+++ pkg/CHNOSZ/man/util.plot.Rd	2019-04-15 06:46:07 UTC (rev 442)
@@ -20,9 +20,9 @@
     mar = NULL, lwd = par("lwd"), side = c(1,2,3,4), 
     mgp = c(1.7, 0.3, 0), cex.axis = par("cex"), col = par("col"),
     yline = NULL, axs = "i", do.box = TRUE, las = 1,
-    xline = NULL, ...)
+    xline = NULL, grid = "", col.grid = "gray", ...)
   thermo.axis(lab = NULL, side = 1:4, line = 1.5, cex = par("cex"),
-    lwd = par("lwd"), col = par("col"))
+    lwd = par("lwd"), col = par("col"), grid = "", col.grid = "gray")
   label.plot(x, xfrac = 0.05, yfrac = 0.95, paren = FALSE,
     italic = FALSE, ...)
   usrfig()
@@ -51,6 +51,8 @@
   \item{do.box}{logical, draw a box around the plot?}
   \item{las}{numeric, style for axis labels}
   \item{xline}{numeric, margin line on which to plot \eqn{x}{x}-axis name}
+  \item{grid}{character, type of grid (\samp{major}, \samp{minor}, or \samp{both})}
+  \item{col.grid}{character, color of the grid lines}
   \item{...}{further arguments passed to \code{par} or \code{mtext}}
   \item{lab}{character, axis label}
   \item{line}{numeric, margin line on which to place axis label or plot title}
@@ -75,6 +77,9 @@
 \code{yline}, if present, denotes the margin line (default \code{\link{par}('mgp')[1]}) where the y-axis name is plotted.
 \code{thermo.axis} is the function that actually adds the axes, including inward-pointing major and minor tick marks (often used for thermodynamic property diagrams).
 
+Use \code{grid} to add a grid to the plot, corresponding to either the major ticks (solid lines), minor ticks (dashed lines), or both.
+The grid can be made by adding \code{grid} argument to \code{\link{diagram}}, or by calling \code{thermo.axis} after \code{diagram} (see example).
+
 \code{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 \code{eout}.
 Values of \T, \P, pH, and \logaH2O, not corresponding to either axis, are also taken from \code{eout}.
@@ -104,4 +109,22 @@
 \code{\link{diagram}} uses \code{thermo.plot.new} to set up a new plot, unless the argument \code{tplot} is set to FALSE in \code{diagram}.
 }
 
+\examples{
+basis(c("H2S", "H2O", "H+", "e-"))
+species(c("HS-", "H2S", "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 = "set3")
+thermo.axis(grid = "major", col.grid = "slategray")
+title(main = 'thermo.axis(grid = "major")')
+par(thermo()$opar)
+par(opar)
+}
+
 \concept{Utility functions}



More information about the CHNOSZ-commits mailing list