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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Apr 16 14:42:20 CEST 2019


Author: jedick
Date: 2019-04-16 14:42:20 +0200 (Tue, 16 Apr 2019)
New Revision: 449

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/R/util.plot.R
   pkg/CHNOSZ/demo/aluminum.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/util.plot.Rd
Log:
thermo.axis(): don't plot axis lines


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2019-04-16 09:50:20 UTC (rev 448)
+++ pkg/CHNOSZ/DESCRIPTION	2019-04-16 12:42:20 UTC (rev 449)
@@ -1,6 +1,6 @@
 Date: 2019-04-16
 Package: CHNOSZ
-Version: 1.3.1-29
+Version: 1.3.1-30
 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/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R	2019-04-16 09:50:20 UTC (rev 448)
+++ pkg/CHNOSZ/R/diagram.R	2019-04-16 12:42:20 UTC (rev 449)
@@ -629,7 +629,13 @@
           else linesout <- contour.lines(predominant, xlim.calc, ylim.calc, 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()
+        has.color <- FALSE
+        if(!identical(unique(fill), "transparent")) has.color <- TRUE
+        if(any(is.na(zs)) & !identical(fill.NA, "transparent")) has.color <- TRUE
+        if(tplot & !add & has.color) {
+          thermo.axis()
+          box()
+        }
       } # done with the 2D plot!
       out2D <- list(namesx=pn$namesx, namesy=pn$namesy)
     } # end if(nd==2)
@@ -661,7 +667,7 @@
   plot.xlim <- c(xlim[1]-xpad,xlim[2]+xpad)
   ymax <- nstrip+0.3
   thermo.plot.new(xlim=plot.xlim,ylim=c(ymin,ymax),xlab=xlab,ylab="",
-      side=c(1,3),mar=par('mar'),do.box=FALSE)
+      side=c(1,3),mar=par('mar'),plot.box=FALSE)
   if(!is.null(xticks)) {
     # mark the positions of the sites on the x-axis
     for(i in 1:5) lines(rep(xticks[i],2),c(ymin,ymin+0.1),lwd=6,col=col[i])

Modified: pkg/CHNOSZ/R/util.plot.R
===================================================================
--- pkg/CHNOSZ/R/util.plot.R	2019-04-16 09:50:20 UTC (rev 448)
+++ pkg/CHNOSZ/R/util.plot.R	2019-04-16 12:42:20 UTC (rev 449)
@@ -2,7 +2,7 @@
 # Functions to create and modify plots
 
 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,
+  mgp=c(1.7,0.3,0),cex.axis=par('cex'),col=par('col'),yline=NULL,axs='i',plot.box=TRUE,
   las=1,xline=NULL, grid = "", col.grid = "gray", ...) {
   # start a new plot with some customized settings
   thermo <- get("thermo", CHNOSZ)
@@ -24,17 +24,17 @@
   par(mar=mar,mgp=mgp,tcl=0.3,las=las,xaxs=axs,yaxs=axs,cex=cex,lwd=lwd,col=col,fg=col, ...)
   plot.new()
   plot.window(xlim=xlim,ylim=ylim)
-  if(do.box) box()
+  if(plot.box) box()
   # labels
   if(is.null(xline)) xline <- mgp[1]
   thermo.axis(xlab,side=1,line=xline,cex=cex.axis,lwd=NULL)
   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, 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)
+  if(1 %in% side) thermo.axis(NULL,side=1,lwd=lwd, grid = grid, col.grid = col.grid, plot.line = !plot.box)
+  if(2 %in% side) thermo.axis(NULL,side=2,lwd=lwd, grid = grid, col.grid = col.grid, plot.line = !plot.box)
+  if(3 %in% side) thermo.axis(NULL,side=3,lwd=lwd, plot.line = !plot.box)
+  if(4 %in% side) thermo.axis(NULL,side=4,lwd=lwd, plot.line = !plot.box)
 }
 
 label.plot <- function(x, xfrac=0.05, yfrac=0.95, paren=FALSE, italic=FALSE, ...) {
@@ -198,18 +198,24 @@
 #   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'), grid = "", col.grid="gray") {
+thermo.axis <- function(lab=NULL,side=1:4,line=1.5,cex=par('cex'),lwd=par('lwd'),col=par('col'), grid = "", col.grid="gray", plot.line=FALSE) {
   if(!is.null(lwd)) {
     for(thisside in side) {
 
       ## get the positions of major tick marks and make grid lines
-      at <- axis(thisside,labels=FALSE,tick=TRUE) 
+      at <- axis(thisside,labels=FALSE,tick=FALSE) 
       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) 
+      # col and col.ticks: plot the tick marks but no line (we make it with box() in thermo.plot.new()) 20190416
+      # mat: don't plot ticks at the plot limits 20190416
+      if(thisside %in% c(1, 3)) pat <- par("usr")[1:2]
+      if(thisside %in% c(2, 4)) pat <- par("usr")[3:4]
+      mat <- setdiff(at, pat)
+      if(plot.line) axis(thisside, at=mat, labels=do.label, tick=TRUE, lwd=lwd, col.axis=col, col=col)
+      else axis(thisside, at=mat, labels=do.label, tick=TRUE, lwd=lwd, col.axis=col, col = NA, col.ticks = col)
 
       ## plot minor tick marks
       # the distance between major tick marks
@@ -252,7 +258,9 @@
       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)
+      at <- setdiff(at, pat)
+      if(plot.line) axis(thisside,labels=FALSE,tick=TRUE,lwd=lwd,col.axis=col,at=at,tcl=tcl, col = col)
+      else axis(thisside,labels=FALSE,tick=TRUE,lwd=lwd,col.axis=col,at=at,tcl=tcl, col = NA, col.ticks = col)
     }
   }
   # rotate labels on side axes

Modified: pkg/CHNOSZ/demo/aluminum.R
===================================================================
--- pkg/CHNOSZ/demo/aluminum.R	2019-04-16 09:50:20 UTC (rev 448)
+++ pkg/CHNOSZ/demo/aluminum.R	2019-04-16 12:42:20 UTC (rev 449)
@@ -59,9 +59,10 @@
 # (averages for each temperature in a single run)
 T <- c(100.1, 100.1, 150.1, 100.1, 150.1, 99.8, 99.8, 200.7, 99.8, 50.1, 75.1, 100.3, 150.1)
 logK <- -c(14.825, 14.735, 13.625, 14.79, 13.665, 14.725, 14.1775, 12.74, 14.4925, 16.8625, 15.61, 14.51, 13.455)
-plot(T, logK, xlim = c(25, 250), ylim = c(-18, -10), xlab = axis.label("T"), ylab = axis.label("logK"))
+thermo.plot.new(c(25, 250), c(-18, -10), axis.label("T"), axis.label("logK"))
+points(T, logK)
+# calculation 1: CHNOSZ default
 T <- 0:250
-# calculation 1: CHNOSZ default
 species <- c("dawsonite", "H2O", "Al(OH)4-", "HCO3-", "Na+", "H+")
 coeffs <- c(-1, -2, 1, 1, 1, 1)
 Daw1 <- subcrt(species, coeffs, T = T)
@@ -85,7 +86,8 @@
 ###########
 # After Tutolo et al., 2014, Fig. 2 (doi:10.1016/j.gca.2014.02.036)
 dat <- read.csv(system.file("extdata/cpetc/TKSS14_Fig2.csv", package = "CHNOSZ"))
-plot(dat, type = "p", xlim = c(3.5, 1.5), ylim = c(-2, 14), xlab = "1000/T(K)", ylab = "pK")
+thermo.plot.new(c(3.5, 1.5), c(-2, 14), quote(1000 / italic(T)*"(K)"), "pK")
+points(dat)
 # plot line: default database
 invTK <- seq(3.5, 1.6, -0.02)
 T <- 1000/invTK - 273.15
@@ -105,7 +107,7 @@
 lines(invTK, pK, col = "blue", lty = 2)
 # add title and legend
 par(xpd = NA)
-title(main = describe.reaction(sres$reaction), cex.main = 1.1)
+title(main = describe.reaction(sres$reaction), cex.main = 1)
 par(xpd = FALSE)
 legend("topright", c("Kaolinite solubility", "After Tutolo et al., 2014 Fig. 2"), bty = "n")
 legend("bottomleft", lty = c(0, 2, 1, 2), pch = c(1, NA, NA, NA), lwd = c(1, 1, 1.5, 1), col = c("black", "blue", "black", "red"),

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2019-04-16 09:50:20 UTC (rev 448)
+++ pkg/CHNOSZ/inst/NEWS	2019-04-16 12:42:20 UTC (rev 449)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.3.1-29 (2019-04-16)
+CHANGES IN CHNOSZ 1.3.1-30 (2019-04-16)
 ---------------------------------------
 
 - Add thermo/stoich.csv.xz (loaded as thermo()$stoich), containing a
@@ -47,6 +47,11 @@
 
 - OBIGT: Move H4SiO4 (Stefánsson, 2001) to AS04.csv (optional data).
 
+- Give thermo.plot.new() argument 'plot.box' (default TRUE) and
+  thermo.axis() argument 'plot.line' (default FALSE) to prevent
+  unecessary plotting of axis lines on a plot with a box. thermo.axis()
+  also avoids plotting tick marks at the plot limits.
+
 CHANGES IN CHNOSZ 1.3.1 (2019-03-02)
 ------------------------------------
 

Modified: pkg/CHNOSZ/man/util.plot.Rd
===================================================================
--- pkg/CHNOSZ/man/util.plot.Rd	2019-04-16 09:50:20 UTC (rev 448)
+++ pkg/CHNOSZ/man/util.plot.Rd	2019-04-16 12:42:20 UTC (rev 449)
@@ -19,10 +19,11 @@
   thermo.plot.new(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,
+    yline = NULL, axs = "i", plot.box = TRUE, las = 1,
     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"), grid = "", col.grid = "gray")
+    lwd = par("lwd"), col = par("col"), grid = "", col.grid = "gray",
+    plot.line = FALSE)
   label.plot(x, xfrac = 0.05, yfrac = 0.95, paren = FALSE,
     italic = FALSE, ...)
   usrfig()
@@ -48,11 +49,12 @@
   \item{col}{character, line color}
   \item{yline}{numeric, margin line on which to plot \eqn{y}{y}-axis name}
   \item{axs}{character, setting for axis limit calculation}
-  \item{do.box}{logical, draw a box around the plot?}
+  \item{plot.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{plot.line}{logical, draw axis 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}



More information about the CHNOSZ-commits mailing list