logKcomp: Read and Compare Equilibrium Constants in GWB Data Files

View source: R/logKcomp.R

logKcompR Documentation

Read and Compare Equilibrium Constants in GWB Data Files

Description

Read values of logK from a data file, and make plots comparing equilibrium constants from two files.

Usage

  logKcomp(file1, file2, type = c("redox", "aqueous"), iTP = 2,
    lab1 = NULL, lab2 = NULL, xlim = NULL, ylim = NULL, plot.it = TRUE)
  readlogK(file, quiet = FALSE)

Arguments

file1

GWB data file

file2

GWB data file

type

Type of species (‘⁠redox⁠’, ‘⁠aqueous⁠’, ‘⁠mineral⁠’, or ‘⁠gas⁠’)

iTP

Which pair of \T, \P values to use (1..8)

lab1

Title for file1 in plot labels

lab2

Title for file2 in plot labels

xlim

Limits for x axis

ylim

Limits for y axis

plot.it

Logical, make a plot?

file

GWB data file

quiet

Logical, reduce messages and printed output?

Details

logKcomp compares \logK values from two GWB thermodynamic data files. The values are taken from the same index of \T, \P pairs in the files. The default for iTP corresponds to 25 \degC and 1 bar for commonly used data files, but it is the user's responsibility to ensure that the files have comparable \T, \P grids.

The values for each indicated type of species are read from file1 and file2 and combined. By default, data for both redox couples and aqueous species are used, but type can be changed to one (or a combination of) redox, aqueous, electron, mineral, and gas.

The function includes only those species that have the same names in both files, or whose mapped names (see logKcalc) are the same. Species are also excluded from the plot (or the returned data frame) if their dissociation reactions are not identical in the two files.

The function returns a ggplot object, which normally results in a plot being made on screen when run interactively. Set plot.it to FALSE to return a data frame of \logK values from the two files instead of making a plot. If file2 is missing, the function doesn't make a plot and instead returns a numeric vector of the \logK values from file1.

A scatterplot is made by plotting values from file1 on the x axis and the difference between values in file1 and file2 on the y axis. Points with differences greater than 1 \logK unit are labeled. The axis labels are generated from the basename of the files, but this can be overriden with lab1 and lab2.

readlogK reads all of the \logK values from the specified file and returns a list with numeric values of \T and \P and lists of \logK values for each type of species.

Examples

# Read logKs from a data file
file <- system.file("extdata/thermo_24elements.tdat", package = "logKcalc")
LOGK <- readlogK(file)
# Show the number of entries
sapply(LOGK, length)

# Compare logKs in two data files
file1 <- system.file("extdata/thermo_24noredox.tdat", package = "logKcalc")
file2 <- system.file("extdata/ThermoGWB_15_6_2020.tdat", package = "logKcalc")
logKcomp(file1, file2)

jedick/logKcalc documentation built on Jan. 19, 2025, 10:41 a.m.