Skip to content
Snippets Groups Projects
Select Git revision
  • fb9e190a7e87d5eec79443b26161bcf91d1c7fb7
  • master default
  • 3-port-RcppTUG
  • 2-refactor-pourbaix
  • v0.0.4
5 results

Rphree_Viz.R

Blame
  • Rphree_Viz.R 3.28 KiB
    ### RedModRphree, functions to perform basic visualization
    ### Licence: LGPL version 2.1
    ### Time-stamp: "Last modified 2018-05-06 19:30:10 delucia"
    
    ##' @title Display the profiles of some variables along a 1D reactive
    ##'     transport simulation
    ##' @param sim The simulation to display
    ##' @param sample optional, time frame position to be desplayed. If
    ##'     omitted, the last is showed
    ##' @param vars optional, character vector containing the names of
    ##'     variables to display (up to 7)
    ##' @param ... further parameters passed to \code{matplot}, such as
    ##'     main, xlab, ylab...
    ##' @return NULL
    ##' @author MDL
    ##' @export
    MatplotSingle <- function(sim, sample=1L, vars=c("Ca","Mg","Calcite","Dolomite"), ...) {
        if(missing(sample))
            sample <- length(sim)
        if (length(vars)>7)
            stopmsg("Please specify up to seven variables")
        
        cols <- c("red", "black","blue","olivedrab3", "orange", "light blue", "grey")[1:length(vars)]
        
        frame <- sim[[sample]]$C
        matplot(frame[,vars], type="l", lwd=2, lty="solid", col=cols, ...)
        legend("topright", vars, text.col=cols, bty="n")
    }
    
    
    
    ##' @title Display the profiles of some variables for 2 reactive
    ##'     transport simulation (one using surrogates)
    ##' @param sur The simulation with surrogate
    ##' @param sim The simulation using only phreeqc
    ##' @param sample optional, time frame position to be desplayed. If
    ##'     omitted, the last is showed
    ##' @param vars optional, character vector containing the names of
    ##'     variables to display (up to 7)
    ##' @param ... further parameters passed to \code{matplot}, such as
    ##'     main, xlab, ylab...
    ##' @return NULL
    ##' @author MDL
    ##' @export
    Matplot <- function(sur, sim, sample=1L, vars=c("Ca","Mg","Calcite","Dolomite"), ...) {
        if(missing(sample))
            sample <- length(sim)
        if (length(vars)>7)
            stopmsg("Please specify up to seven variables")
        
        cols <- c("red", "black","blue","olivedrab3", "orange", "light blue", "grey")[1:length(vars)]
        
        rs <- sur[[sample]]$C
        rn <- sim[[sample]]$C
        matplot(rn[,vars], type="l", lwd=2, lty="solid", col=cols, ...)
        matplot(rs[,vars], type="l", lwd=2, lty="dashed",col=cols, add=TRUE)
        legend("topright", vars, text.col=cols, bty="n")
    }
    
    ##' @title Scatter plots of phreeqc simulations vs surrogate response
    ##' @param mod list of regression models, one per variable
    ##' @param res the matrix or data.frame of the results
    ##' @param des the matrix or data.frame of the design (upon which the surrogates are called)
    ##' @param sample optional, indeces of the rows to include in the plot
    ##' @param column logical, if TRUE there are 2 columns, if FALSE 2 rows of the plot
    ##' @param ... further parameters passed internally to \code{plot}
    ##' @return NULL
    ##' @author MDL
    ##' @export
    PlotModsInSample <- function(mod, res, des, sample=seq(1,nrow(res)), column=TRUE, ...) {
        nres <- ncol(res)
        ## how many rows in the mfrow plot?
        nr <- floor(nres/2)+nres%%2
        design <- des[sample,]
        result <- res[sample,]
        
        if (column)
            par(mfrow=c(nr,2))
        else
            par(mfrow=c(2,nr))
        for (i in seq_along(mod)) {
            plot(result[,i], predict(mod[[i]], design),"p",pch=3, main=names(mod)[i],
                 xlab="Full physics", ylab="Surrogate", ...)
            abline(0,1,lty="dashed",col="grey")
        }
    }