[CHNOSZ-commits] r122 - in pkg/CHNOSZ: . R demo inst man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jan 22 11:27:32 CET 2017
Author: jedick
Date: 2017-01-22 11:27:31 +0100 (Sun, 22 Jan 2017)
New Revision: 122
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/diagram.R
pkg/CHNOSZ/demo/copper.R
pkg/CHNOSZ/demo/mosaic.R
pkg/CHNOSZ/inst/NEWS
pkg/CHNOSZ/man/diagram.Rd
pkg/CHNOSZ/man/mosaic.Rd
Log:
diagram() draws smoother-looking boundary lines
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/DESCRIPTION 2017-01-22 10:27:31 UTC (rev 122)
@@ -1,6 +1,6 @@
-Date: 2017-01-21
+Date: 2017-01-22
Package: CHNOSZ
-Version: 1.0.8-10
+Version: 1.0.8-11
Title: Chemical Thermodynamics and Activity Diagrams
Author: Jeffrey Dick
Maintainer: Jeffrey Dick <j3ffdick at gmail.com>
Modified: pkg/CHNOSZ/R/diagram.R
===================================================================
--- pkg/CHNOSZ/R/diagram.R 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/R/diagram.R 2017-01-22 10:27:31 UTC (rev 122)
@@ -18,7 +18,7 @@
# sizes
cex=par("cex"), cex.names=1, cex.axis=par("cex"),
# line styles
- lty=NULL, lwd=par("lwd"), dotted=0,
+ lty=NULL, lwd=par("lwd"), dotted=NULL,
# colors
bg=par("bg"), col=par("col"), col.names=par("col"), fill=NULL,
# labels
@@ -353,6 +353,35 @@
if(!is.null(xrange)) xs <- clipfun(xs, xrange)
lines(xs, ys, col=col, lwd=lwd)
}
+ ## new line plotting function 20170122
+ contour.lines <- function(predominant, xlim, ylim, lty, col, lwd) {
+ # the x and y values
+ xs <- seq(xlim[1], xlim[2], length.out=dim(predominant)[1])
+ ys <- seq(ylim[1], ylim[2], length.out=dim(predominant)[2])
+ # reverse any axis that has decreasing values
+ if(diff(xlim) < 0) {
+ predominant <- predominant[nrow(predominant):1, ]
+ xs <- rev(xs)
+ }
+ if(diff(ylim) < 0) {
+ predominant <- predominant[, ncol(predominant):1]
+ ys <- rev(ys)
+ }
+ # the categories (species/groups/etc) on the plot
+ zvals <- unique(as.vector(predominant))
+ # take each possible pair
+ for(i in 1:(length(zvals)-1)) {
+ for(j in (i+1):length(zvals)) {
+ z <- predominant
+ # draw contours only for this pair
+ z[!z %in% c(zvals[i], zvals[j])] <- NA
+ # 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)
+ }
+ }
+ }
## label plot function
# calculate coordinates for field labels
plot.names <- function(out, xs, ys, names) {
@@ -421,6 +450,7 @@
if(!is.null(fill)) fill.color(xs, ys, zs, fill, ngroups)
pn <- plot.names(zs, xs, ys, names)
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)
} # done with the 2D plot!
out2D <- list(lx=pn$lx, ly=pn$ly, is=pn$is)
} # end if(nd==2)
Modified: pkg/CHNOSZ/demo/copper.R
===================================================================
--- pkg/CHNOSZ/demo/copper.R 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/demo/copper.R 2017-01-22 10:27:31 UTC (rev 122)
@@ -54,7 +54,7 @@
}
# add glycine ionization lines
-d <- diagram(m$A.bases, add=TRUE, col="darkblue", dotted=c(2, 3), names=NULL)
+d <- diagram(m$A.bases, add=TRUE, col="darkblue", lty=3, names=NULL)
text(d$lx, -0.5, Gly, col="darkblue")
# add water lines and title and re-draw a box around the plot
Modified: pkg/CHNOSZ/demo/mosaic.R
===================================================================
--- pkg/CHNOSZ/demo/mosaic.R 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/demo/mosaic.R 2017-01-22 10:27:31 UTC (rev 122)
@@ -24,15 +24,15 @@
# compare with the plot in Garrels and Christ, 1965
m1 <- mosaic(bases, bases2, TRUE, pH=pH, Eh=Eh, T=T)
# make a diagram and add water stability lines
-diagram(m1$A.species)
+diagram(m1$A.species, lwd=2)
water.lines("pH", "Eh", T=convert(T, "K"), col="seagreen", lwd=1.5)
# show lines for Fe(aq) = 10^-4 M
species(c("Fe+2", "Fe+3"), -4)
m2 <- mosaic(bases, bases2, TRUE, pH=pH, Eh=Eh, T=T)
-diagram(m2$A.species, add=TRUE, names=NULL, dotted=3)
+diagram(m2$A.species, add=TRUE, names=NULL)
title(main=paste("Iron oxides, sulfides and carbonate in water, log(total S) = -6,",
"log(total C)=0, after Garrels and Christ, 1965", sep="\n"))
# overlay the carbonate basis species predominance fields
-diagram(m1$A.bases2, add=TRUE, col="blue", col.names="blue", dotted=3)
+diagram(m1$A.bases2, add=TRUE, col="blue", col.names="blue", lty=3)
# reset the database, as it was changed in this example
data(thermo)
Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/inst/NEWS 2017-01-22 10:27:31 UTC (rev 122)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.0.8-10 (2017-01-21)
+CHANGES IN CHNOSZ 1.0.8-11 (2017-01-22)
---------------------------------------
- Add "AA" as a keyword for preset species in basis() (cysteine,
@@ -31,6 +31,10 @@
(accession, name, organism) into columns of the output data frame
(protein, abbrv, organism).
+- diagram() draws smoother boundary lines (with contour(); 'lty' is
+ usable), at the expense of not being precisely aligned with the grid
+ used for plotting colors. For the old behavior, use dotted=0.
+
CHANGES IN CHNOSZ 1.0.8 (2016-05-28)
------------------------------------
Modified: pkg/CHNOSZ/man/diagram.Rd
===================================================================
--- pkg/CHNOSZ/man/diagram.Rd 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/man/diagram.Rd 2017-01-22 10:27:31 UTC (rev 122)
@@ -13,7 +13,7 @@
xrange=NULL, mar=NULL, yline=par("mgp")[1]+0.7, 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=0,
+ lty=NULL, lwd=par("lwd"), dotted=NULL,
bg=par("bg"), col=par("col"), col.names=par("col"), fill=NULL,
names=NULL, main=NULL, legend.x="topright", add=FALSE, plot.it=TRUE,
tplot=TRUE, ...)
@@ -85,8 +85,13 @@
On 2-D diagrams, the fields represent the species with the highest equilibrium activity.
\code{fill} determines the color of the predominance fields, \code{col} that of the boundary lines.
By default, \code{\link{heat.colors}} are used to fill the predominance fields in diagrams on the screen plot device.
-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.
+As of CHNOSZ 1.0.8-11, a new default line-drawing procedure has been implemented.
+This uses \code{\link{contour}} to draw smooth-looking diagonal and curved lines, at the expense of not coinciding exactly with the the rectangular grid (which is still 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.
+
\code{normalize} and \code{as.residue} apply only to the 2-D diagrams, and only when \code{eout} is the output from \code{affinity}.
With \code{normalize}, the activity boundaries are calculated as between the residues of the species (the species divided by the balance coefficients), then the activities are rescaled to the whole species formulas.
With \code{as.residue}, the activity boundaries are calculated as between the residues of the species, and no rescaling is performed.
Modified: pkg/CHNOSZ/man/mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/mosaic.Rd 2017-01-21 12:53:11 UTC (rev 121)
+++ pkg/CHNOSZ/man/mosaic.Rd 2017-01-22 10:27:31 UTC (rev 122)
@@ -63,16 +63,16 @@
# calculate affinities using the predominant basis species
m1 <- mosaic(bases, pH=pH, Eh=Eh, T=T)
# make a diagram and add water stability lines
-diagram(m1$A.species)
+diagram(m1$A.species, lwd=2)
water.lines("pH", "Eh", T=convert(T, "K"), col="seagreen", lwd=1.5)
# show lines for Fe(aq) = 10^-4 M
species(c("Fe+2", "Fe+3"), -4)
m2 <- mosaic(bases, pH=pH, Eh=Eh, T=T)
-diagram(m2$A.species, add=TRUE, names=NULL, dotted=3)
+diagram(m2$A.species, add=TRUE, names=NULL)
title(main=paste("Iron oxides and sulfides in water, log(total S) = -6",
"After Garrels and Christ, 1965", sep="\n"))
# we could overlay the basis species predominance fields
-#diagram(m1$A.bases, add=TRUE, col="blue", col.names="blue", dotted=3)
+#diagram(m1$A.bases, add=TRUE, col="blue", col.names="blue", lty=3)
}
\references{
More information about the CHNOSZ-commits
mailing list