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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 16 18:12:39 CET 2017


Author: jedick
Date: 2017-11-16 18:12:39 +0100 (Thu, 16 Nov 2017)
New Revision: 294

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/diagram.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/diagram.Rd
Log:
diagram(): add spline.method argument to control plotting 1-D lines as splines


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2017-11-16 15:42:37 UTC (rev 293)
+++ pkg/CHNOSZ/DESCRIPTION	2017-11-16 17:12:39 UTC (rev 294)
@@ -1,6 +1,6 @@
-Date: 2017-11-13
+Date: 2017-11-17
 Package: CHNOSZ
-Version: 1.1.3
+Version: 1.1.3-1
 Title: Thermodynamic Calculations for Geobiochemistry
 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	2017-11-16 15:42:37 UTC (rev 293)
+++ pkg/CHNOSZ/R/diagram.R	2017-11-16 17:12:39 UTC (rev 294)
@@ -9,6 +9,7 @@
 #source("equilibrate.R")
 #source("util.plot.R")
 #source("util.character.R")
+#source("util.misc.R")
 
 diagram <- function(
   # primary input
@@ -23,7 +24,7 @@
   # sizes
   cex=par("cex"), cex.names=1, cex.axis=par("cex"),
   # line styles
-  lty=NULL, lwd=par("lwd"), dotted=NULL, 
+  lty=NULL, lwd=par("lwd"), dotted=NULL, spline.method=NULL,
   # colors
   col=par("col"), col.names=par("col"), fill=NULL,
   fill.NA="slategray1", limit.water=TRUE,
@@ -262,10 +263,10 @@
 
       ### 1-D diagram - lines for properties or chemical activities
       xvalues <- eout$vals[[1]]
+      if(missing(xlim)) xlim <- range(xvalues)  # TODO: this is backward if the vals are not increasing
       # initialize the plot
       if(!add) {
         if(missing(xlab)) xlab <- axis.label(eout$vars[1], basis=eout$basis, use.molality=use.molality)
-        if(missing(xlim)) xlim <- range(xvalues)  # TODO: this is backward if the vals are not increasing
         if(missing(ylab)) ylab <- axis.label(plotvar, units="", use.molality=use.molality)
         # to get range for y-axis, use only those points that are in the xrange
         if(is.null(ylim)) {
@@ -278,7 +279,17 @@
         else plot(0, 0, type="n", xlim=xlim, ylim=ylim, xlab=xlab, ylab=ylab, ...)
       }
       # draw the lines
-      for(i in 1:length(plotvals)) lines(xvalues, plotvals[[i]], col=col[i], lty=lty[i], lwd=lwd[i])
+      spline.n <- 256 # the number of values at which to calculate splines
+      if(is.null(spline.method) | length(xvalues) > spline.n) {
+        for(i in 1:length(plotvals)) lines(xvalues, plotvals[[i]], col=col[i], lty=lty[i], lwd=lwd[i])
+      } else {
+        # plot splines instead of lines connecting the points 20171116
+        spline.x <- seq(xlim[1], xlim[2], length.out=spline.n)
+        for(i in 1:length(plotvals)) {
+          spline.y <- splinefun(xvalues, plotvals[[i]], method=spline.method)(spline.x)
+          lines(spline.x, spline.y, col=col[i], lty=lty[i], lwd=lwd[i])
+        }
+      }
       if(!add & !is.null(legend.x)) {
         # 20120521: use legend.x=NA to label lines rather than make legend
         if(is.na(legend.x)) {

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2017-11-16 15:42:37 UTC (rev 293)
+++ pkg/CHNOSZ/inst/NEWS	2017-11-16 17:12:39 UTC (rev 294)
@@ -1,3 +1,10 @@
+CHANGES IN CHNOSZ 1.1.3-1 (2017-11-17)
+--------------------------------------
+
+- Lines in 1-D diagram()s can optionally be drawn as splines using the
+  method for splinefun() given in the 'spline.method' argument (the
+  default of NULL means no splines).
+
 CHANGES IN CHNOSZ 1.1.3 (2017-11-13)
 ------------------------------------
 

Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd	2017-11-16 15:42:37 UTC (rev 293)
+++ pkg/CHNOSZ/man/diagram.Rd	2017-11-16 17:12:39 UTC (rev 294)
@@ -14,7 +14,7 @@
     xrange=NULL, mar=NULL, yline=par("mgp")[1]+0.3, side=1:4,
     ylog=TRUE, xlim=NULL, ylim=NULL, xlab=NULL, ylab=NULL,
     cex=par("cex"), cex.names=1, cex.axis=par("cex"),
-    lty=NULL, lwd=par("lwd"), dotted=NULL,
+    lty=NULL, lwd=par("lwd"), dotted=NULL, spline.method = NULL,
     col=par("col"), col.names=par("col"), fill=NULL,
     fill.NA="slategray1", limit.water=TRUE,
     names=NULL, main=NULL, legend.x=NA, format.names=TRUE, adj=0.5, dy=0,
@@ -47,6 +47,7 @@
   \item{lty}{numeric, line types to be used in plots}
   \item{lwd}{numeric, line width}
   \item{dotted}{numeric, how often to skip plotting points on predominance field boundaries (to gain the effect of dotted or dashed boundary lines)}
+  \item{spline.method}{character, method used in \code{\link{splinefun}}}
   \item{col}{character, color of activity lines (1D diagram) or predominance field boundaries (2D diagram), or colors of bars in a strip diagram (\code{strip})}
   \item{col.names}{character, colors for labels of species}
   \item{fill}{character, colors used to fill predominance fields}
@@ -101,6 +102,7 @@
 If \code{alpha} is TRUE, the fractional degrees of formation (ratios of activities to total activity) are plotted.
 Or, setting \code{alpha} to \samp{balance} allows the activities to be multiplied by the number of the balancing component; this is useful for making \dQuote{percent carbon} diagrams where the species differ in carbon number.
 The line type and line width can be controlled with \code{lty} and \code{lwd}, respectively.
+To connect the points with splines instead of lines, set \code{spline.method} to one of the methods in \code{\link{splinefun}}.
 }
 
 \section{2-D diagrams}{



More information about the CHNOSZ-commits mailing list