From 32686b04fd6355845bb423c42442b1d47cf54fb1 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 18 Aug 2015 11:23:08 -0500 Subject: [PATCH 1/5] Updated NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 67765ee0..caa37af1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +EGRET 2.3.1 +=========== +* Removed unnecessary disclaimer. + EGRET 2.2.0 =========== * Minor bug fixes From 7e140a508f427e00e07acc4274c6bab7b486116f Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 18 Aug 2015 11:29:03 -0500 Subject: [PATCH 2/5] Updated example to check if uncensored segments were being drawn correctly. They are. --- R/censoredSegments.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/censoredSegments.R b/R/censoredSegments.R index 58fdc2a4..ad67dd91 100644 --- a/R/censoredSegments.R +++ b/R/censoredSegments.R @@ -14,7 +14,7 @@ #' @export #' @examples #' x <- c(1,2,3,4,5,6) -#' y <- c(1,3,4,3.3,4.4,2) +#' y <- c(1,3,4,3.3,4.4,7) #' xlim <- c(min(x)*.75,max(x)*1.25) #' ylim <- c(0,1.25*max(y)) #' xlab <- "Date" @@ -28,9 +28,9 @@ #' plotTitle="Test" #' ) #' yBottom <- 0 -#' yLow <- c(NA,3,4,3.3,4.4,2) -#' yHigh <- c(1,3,4,3.3,4.4,2) -#' Uncen <- c(0,1,1,1,1,1) +#' yLow <- c(NA,3,4,3.3,4,7) +#' yHigh <- c(1,3,4,3.3,5,NA) +#' Uncen <- c(0,1,1,1,0,0) #' censoredSegments(yBottom=yBottom,yLow=yLow,yHigh=yHigh,x=x,Uncen=Uncen) censoredSegments <- function(yBottom,yLow,yHigh,x,Uncen,col="black",lwd=1){ yLowVal<-ifelse(is.na(yLow),yBottom,yLow) #yLow would be NA if "simple" censored....so giving it a value here From 468d4493283b5bf07761f143bbe2812c7d378d02 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Fri, 4 Sep 2015 09:46:19 -0500 Subject: [PATCH 3/5] Up version. --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d4cb5995..6f0afdda 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: EGRET Type: Package Title: Exploration and Graphics for RivEr Trends (EGRET) -Version: 2.3.1 +Version: 2.3.2 Authors@R: c( person("Robert", "Hirsch", role = c("aut"), email = "rhirsch@usgs.gov"), person("Laura", "DeCicco", role = c("aut","cre"), @@ -10,7 +10,7 @@ Description: Statistics and graphics for streamflow history, water quality trends, and the statistical modeling algorithm: Weighted Regressions on Time, Discharge, and Season (WRTDS). License: CC0 -Date: 2015-07-23 +Date: 2015-09-04 Depends: R (>= 3.0) Imports: From 17061c16b7ce003e56a79d8c338d2a9a65c71b74 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 8 Sep 2015 14:58:55 -0500 Subject: [PATCH 4/5] First pass at randomized censored values. --- DESCRIPTION | 7 ++-- NAMESPACE | 2 + R/boxConcThree.R | 27 +++++++++---- R/boxResidMonth.R | 26 +++++++++---- R/fluxBiasEight.R | 21 +++++----- R/makeRandomResiduals.R | 40 +++++++++++++++++++ R/plotConcPred.R | 56 ++++++++++++++++++--------- R/plotFluxPred.R | 57 ++++++++++++++++++---------- R/plotResidPred.R | 61 ++++++++++++++++++++++------- R/plotResidQ.R | 78 ++++++++++++++++++++++++-------------- R/plotResidTime.R | 71 +++++++++++++++++++++++----------- man/boxConcThree.Rd | 4 +- man/boxResidMonth.Rd | 4 +- man/censoredSegments.Rd | 8 ++-- man/fluxBiasMulti.Rd | 5 ++- man/makeAugmentedSample.Rd | 26 +++++++++++++ man/plotConcPred.Rd | 5 ++- man/plotFluxPred.Rd | 5 ++- man/plotResidPred.Rd | 6 ++- man/plotResidQ.Rd | 4 +- man/plotResidTime.Rd | 4 +- 21 files changed, 376 insertions(+), 141 deletions(-) create mode 100644 R/makeRandomResiduals.R create mode 100644 man/makeAugmentedSample.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 6f0afdda..857f192a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: EGRET Type: Package Title: Exploration and Graphics for RivEr Trends (EGRET) -Version: 2.3.2 +Version: 2.4.1 Authors@R: c( person("Robert", "Hirsch", role = c("aut"), email = "rhirsch@usgs.gov"), person("Laura", "DeCicco", role = c("aut","cre"), @@ -10,7 +10,7 @@ Description: Statistics and graphics for streamflow history, water quality trends, and the statistical modeling algorithm: Weighted Regressions on Time, Discharge, and Season (WRTDS). License: CC0 -Date: 2015-09-04 +Date: 2015-09-08 Depends: R (>= 3.0) Imports: @@ -22,7 +22,8 @@ Imports: utils, graphics, stats, - grDevices + grDevices, + truncnorm Suggests: xtable, knitr, diff --git a/NAMESPACE b/NAMESPACE index b7a9e608..8eea78eb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -40,6 +40,7 @@ export(is.egret) export(logPretty1) export(logPretty3) export(makeAnnualSeries) +export(makeAugmentedSample) export(mergeReport) export(modelEstimation) export(monthInfo) @@ -115,3 +116,4 @@ import(survival) import(utils) importFrom(fields,interp.surface) importFrom(lubridate,decimal_date) +importFrom(truncnorm,rtruncnorm) diff --git a/R/boxConcThree.R b/R/boxConcThree.R index d07ce3c2..17904b33 100644 --- a/R/boxConcThree.R +++ b/R/boxConcThree.R @@ -18,6 +18,7 @@ #' @param cex numerical value giving the amount by which plotting symbols should be magnified #' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE. #' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @seealso \code{\link[graphics]{boxplot}} @@ -31,7 +32,7 @@ #' boxConcThree(eList) boxConcThree<-function (eList, tinyPlot=FALSE, printTitle = TRUE, moreTitle = "WRTDS",customPar=FALSE, - font.main=2,cex=0.8,cex.main = 1.1, cex.axis = 1.1,...){ + font.main=2,cex=0.8,cex.main = 1.1, cex.axis = 1.1,rResid=FALSE,...){ localINFO <- getInfo(eList) localSample <- getSample(eList) @@ -56,7 +57,6 @@ boxConcThree<-function (eList, tinyPlot=FALSE, index2 <- rep(2, nS) index3 <- rep(3, nD) index <- c(index1, index2,index3) - concV <- c(localSample$ConcAve,localSample$ConcHat,localDaily$ConcDay) plotTitle <- if (printTitle) { paste(localINFO$shortName, ",", localINFO$paramShortName, @@ -65,10 +65,6 @@ boxConcThree<-function (eList, tinyPlot=FALSE, "" } - yMax<-max(concV,na.rm=TRUE) - yTicks<-yPretty(yMax) - yTop<-yTicks[length(yTicks)] - if (tinyPlot) { yLab <- paste("Conc. (",localINFO$param.units,")",sep="") if (!customPar) par(mar=c(4,5,1,0.1),tcl=0.5,cex.lab=cex.axis) @@ -83,13 +79,28 @@ boxConcThree<-function (eList, tinyPlot=FALSE, name3 <- "All day\nestimates" groupNames <- c(name1,name2,name3) + if(!rResid){ + concV <- c(localSample$ConcAve,localSample$ConcHat,localDaily$ConcDay) + + } else { + if(!("rObserved" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + concV <- c(localSample$rObserved,localSample$ConcHat,localDaily$ConcDay) + } + + yMax<-max(concV,na.rm=TRUE) + yTicks<-yPretty(yMax) + yTop<-yTicks[length(yTicks)] + boxplot(concV ~ index,varwidth=TRUE, names=groupNames,xlab="",ylab=yLab, ylim=c(0,yTop),axes=FALSE, main=plotTitle,font.main=font.main,cex=cex, cex.main=cex.main, las=1,yaxs="i", - ...) + ...) axis(1,tcl=0.5,at=c(1,2,3),labels=groupNames,cex.axis=cex.axis*0.5454) axis(2,tcl=0.5,las=1,at=yTicks,cex.axis=cex.axis) @@ -97,5 +108,5 @@ boxConcThree<-function (eList, tinyPlot=FALSE, axis(4,tcl=0.5,at=yTicks,labels=FALSE) box() if (!tinyPlot) mtext(title2,side=3,line=-1.5) - + invisible(eList) } \ No newline at end of file diff --git a/R/boxResidMonth.R b/R/boxResidMonth.R index df018fa2..5ede8c5a 100644 --- a/R/boxResidMonth.R +++ b/R/boxResidMonth.R @@ -22,6 +22,7 @@ #' @param font.main font to be used for plot main titles #' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function #' @param las numeric in {0,1,2,3}; the style of axis labels +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @seealso \code{\link[graphics]{boxplot}} @@ -35,7 +36,7 @@ #' boxResidMonth(eList) boxResidMonth<-function(eList, stdResid = FALSE, las=1, printTitle = TRUE, cex=0.8, cex.axis=1.1, cex.main=1.1, - font.main=2, tinyPlot=FALSE, customPar=FALSE,...) { + font.main=2, tinyPlot=FALSE, customPar=FALSE,rResid=FALSE,...) { localINFO <- getInfo(eList) localSample <- getSample(eList) @@ -63,18 +64,28 @@ boxResidMonth<-function(eList, stdResid = FALSE, las=1, } plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\nBoxplots of residuals by month") else "" - resid<-log(localSample$ConcAve) - localSample$yHat - resid<-if(stdResid) resid/localSample$SE else resid + + if(!rResid){ + resid<-log(localSample$ConcAve) - localSample$yHat + } else { + if(!("rResid" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + resid <- localSample$rResid + } + + if(stdResid) { + resid<- resid/localSample$SE + } singleMonthList <- sapply(c(1:12),function(x){monthInfo[[x]]@monthAbbrev}) namesListFactor <- factor(singleMonthList, levels=singleMonthList) monthList <- as.character(apply(localSample, 1, function(x) monthInfo[[as.numeric(x[["Month"]])]]@monthAbbrev)) monthList <- factor(monthList, namesListFactor) - - tempDF <- data.frame(month=monthList, resid=resid) - - boxplot(tempDF$resid ~ tempDF$month, + + boxplot(resid ~ monthList, varwidth=TRUE, xlab="Month",ylab=yLab, main=plotTitle, @@ -86,4 +97,5 @@ boxResidMonth<-function(eList, stdResid = FALSE, las=1, ...) abline(h=0) if (!tinyPlot) mtext(title2,side=3,line=-1.5) + invisible(eList) } \ No newline at end of file diff --git a/R/fluxBiasEight.R b/R/fluxBiasEight.R index 294abc01..7aaf1708 100644 --- a/R/fluxBiasEight.R +++ b/R/fluxBiasEight.R @@ -21,12 +21,14 @@ #' @param cex.axis magnification to be used for axis annotation relative to the current setting of cex #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot censored residuals as segments, or randomized points. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @export #' @examples #' eList <- Choptank_eList #' fluxBiasMulti(eList) +#' fluxBiasMulti(eList, rResid=TRUE) #' # Water year: #' \dontrun{ #' pdf("fluxBiasMulti.pdf", height=9, width=8) @@ -40,7 +42,7 @@ #' } fluxBiasMulti<-function (eList, qUnit = 2, fluxUnit = 3, moreTitle = "WRTDS", cex = 0.7, cex.axis = 1.1,cex.main=1.1, - col="black", lwd=1,...){ + col="black", lwd=1,rResid=FALSE,...){ localINFO <- getInfo(eList) localSample <- getSample(eList) @@ -69,29 +71,29 @@ fluxBiasMulti<-function (eList, qUnit = 2, fluxUnit = 3, moreTitle = "WRTDS", title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) par(oma = c(0, 10, 4, 10),mfrow=c(4,2)) - plotResidPred(eList, + eList <- plotResidPred(eList, stdResid = FALSE, tinyPlot=TRUE, printTitle = FALSE,cex=cex, - cex.axis = cex.axis, col=col,lwd=lwd,...) + cex.axis = cex.axis, col=col,lwd=lwd, rResid=rResid,...) plotResidQ(eList, qUnit, tinyPlot = TRUE, printTitle = FALSE,cex=cex, - cex.axis = cex.axis, col=col,lwd=lwd,...) + cex.axis = cex.axis, col=col,lwd=lwd, rResid=rResid,...) plotResidTime(eList, printTitle = FALSE, tinyPlot=TRUE,cex=cex, - cex.axis = cex.axis, col=col,lwd=lwd,...) + cex.axis = cex.axis, col=col,lwd=lwd, rResid=rResid,...) boxResidMonth(eList, printTitle = FALSE, tinyPlot=TRUE,cex=cex, - cex.axis = cex.axis,lwd=lwd,...) + cex.axis = cex.axis,lwd=lwd, rResid=rResid,...) boxConcThree(eList, localINFO = localINFO, printTitle=FALSE, tinyPlot=TRUE,cex=cex, - cex.axis = cex.axis, lwd=lwd,...) + cex.axis = cex.axis, lwd=lwd, rResid=rResid,...) plotConcPred(eList, printTitle=FALSE, tinyPlot=TRUE,cex=cex, - cex.axis = cex.axis, col=col,lwd=lwd,...) + cex.axis = cex.axis, col=col,lwd=lwd, rResid=rResid,...) boxQTwice(eList, printTitle = FALSE, qUnit = qUnit,tinyPlot=TRUE,cex=cex, cex.axis = cex.axis, lwd=lwd,...) plotFluxPred(eList, fluxUnit, tinyPlot = TRUE, printTitle = FALSE,cex=cex, - cex.axis = cex.axis, col=col,lwd=lwd,...) + cex.axis = cex.axis, col=col,lwd=lwd, rResid=rResid,...) fluxBias <- fluxBiasStat(localSample) fB <- as.numeric(fluxBias[3]) fB <- format(fB, digits = 3) @@ -105,5 +107,6 @@ fluxBiasMulti<-function (eList, qUnit = 2, fluxUnit = 3, moreTitle = "WRTDS", } par(mfcol = c(1, 1), oma = c(0, 0, 0, 0)) + invisible(eList) } diff --git a/R/makeRandomResiduals.R b/R/makeRandomResiduals.R new file mode 100644 index 00000000..0b8f41a2 --- /dev/null +++ b/R/makeRandomResiduals.R @@ -0,0 +1,40 @@ +#' Create Randomized Residuals and Observations +#' +#' This function is used to add two columns to the Sample data frame: rResid and rObserved. +#' rResid is the randomized residual value computed in log concentration units, and rObserved +#' is the randomized 'observed' value of concentration in concentration units. +#' +#' @param eList named list with at least the Daily dataframe +#' @keywords water-quality statistics +#' @return eList named list with modified Daily data frame. +#' @export +#' @importFrom truncnorm rtruncnorm +#' @examples +#' eList <- Choptank_eList +#' eList <- makeAugmentedSample(eList) +makeAugmentedSample <- function(eList){ + + localSample <- eList$Sample + numSamples<-length(localSample$Uncen) + a <- ifelse(localSample$Uncen==0&!is.na(localSample$ConcLow),log(localSample$ConcLow)-localSample$yHat,-Inf) + b <- ifelse(localSample$Uncen==1,+Inf,log(localSample$ConcHigh) - localSample$yHat) + mean <- ifelse(localSample$Uncen==1,log(localSample$ConcHigh) - localSample$yHat,0) + sd <- ifelse(localSample$Uncen==1,0,localSample$SE) + localSample$rResid<-truncnorm::rtruncnorm(numSamples,a,b,mean,sd) + localSample$rObserved <- exp(localSample$rResid + localSample$yHat) + + eList <- as.egret(eList$INFO, eList$Daily, localSample, eList$surfaces) + return(eList) +} + +# makeRandomResiduals <- function(eList){ +# localSample <- eList$Sample +# numSamples<-length(localSample$Uncen) +# a <- ifelse(localSample$Uncen==0&!is.na(localSample$ConcLow),log(localSample$ConcLow)-localSample$yHat,-Inf) +# b <- ifelse(localSample$Uncen==1,+Inf,log(localSample$ConcHigh) - localSample$yHat) +# mean <- ifelse(localSample$Uncen==1,log(localSample$ConcHigh) - localSample$yHat,0) +# sd <- ifelse(localSample$Uncen==1,0,localSample$SE) +# localSample$rResid<-truncnorm::rtruncnorm(numSamples,a,b,mean,sd) +# eList <- as.egret(eList$INFO, eList$Daily, localSample, eList$surfaces) +# return(eList) +# } \ No newline at end of file diff --git a/R/plotConcPred.R b/R/plotConcPred.R index 8a4afcf3..2bf7f24e 100644 --- a/R/plotConcPred.R +++ b/R/plotConcPred.R @@ -18,6 +18,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @seealso \code{\link{selectDays}}, \code{\link{genericEGRETDotPlot}} @@ -27,16 +28,13 @@ #' # Water year: #' plotConcPred(eList) #' plotConcPred(eList, logScale=TRUE) +#' plotConcPred(eList, logScale=TRUE, rResid=TRUE) #' # Graphs consisting of Jun-Aug #' eList <- setPA(eList, paStart=6,paLong=3) #' plotConcPred(eList) plotConcPred<-function(eList, concMax = NA, logScale=FALSE, printTitle = TRUE,tinyPlot=FALSE,cex=0.8, cex.axis=1.1, - cex.main=1.1, customPar=FALSE,col="black",lwd=1,...){ - # this function shows observed versus predicted concentration - # predicted concentration on the x-axis (these include the bias correction), - # observed concentration on y-axis - # these predictions are from a "leave-one-out" cross validation application of WRTDS + cex.main=1.1, customPar=FALSE,col="black",lwd=1,rResid=FALSE,...){ localINFO <- getInfo(eList) localSample <- getSample(eList) @@ -54,8 +52,7 @@ plotConcPred<-function(eList, concMax = NA, logScale=FALSE, title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) x<-localSample$ConcHat - yLow<-localSample$ConcLow - yHigh<-localSample$ConcHigh + Uncen<-localSample$Uncen if(tinyPlot){ @@ -79,20 +76,43 @@ plotConcPred<-function(eList, concMax = NA, logScale=FALSE, plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Observed versus Estimated Concentration") else "" xInfo <- generalAxis(x=x, minVal=minXLow, maxVal=concMax, tinyPlot=tinyPlot,logScale=logScale) - yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, tinyPlot=tinyPlot,logScale=logScale) - ############################ + if(!rResid){ + yLow<-localSample$ConcLow + yHigh<-localSample$ConcHigh + + yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, tinyPlot=tinyPlot,logScale=logScale) - genericEGRETDotPlot(x=x, y=yHigh, - xTicks=xInfo$ticks, yTicks=yInfo$ticks, - xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), - xlab=xLab, ylab=yLab,log=logVariable, - plotTitle=plotTitle, oneToOneLine=TRUE, - cex.axis=cex.axis,cex.main=cex.main,cex=cex, - tinyPlot=tinyPlot,customPar=customPar,col=col,lwd=lwd,... + genericEGRETDotPlot(x=x, y=yHigh, + xTicks=xInfo$ticks, yTicks=yInfo$ticks, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yLab,log=logVariable, + plotTitle=plotTitle, oneToOneLine=TRUE, + cex.axis=cex.axis,cex.main=cex.main,cex=cex, + tinyPlot=tinyPlot,customPar=customPar,col=col,lwd=lwd,... + ) + + censoredSegments(yBottom=yInfo$bottom, yLow=yLow, yHigh=yHigh, x=x, Uncen=Uncen,col=col,lwd=lwd) + } else { + if(!("rObserved" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + yHigh <- localSample$rObserved + + yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, tinyPlot=tinyPlot,logScale=logScale) + + genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1], + xTicks=xInfo$ticks, yTicks=yInfo$ticks, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yLab,log=logVariable, + plotTitle=plotTitle, oneToOneLine=TRUE, + cex.axis=cex.axis,cex.main=cex.main,cex=cex, + tinyPlot=tinyPlot,customPar=customPar,col=col,lwd=lwd,... ) + points(x=x[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col) + } - censoredSegments(yBottom=yInfo$bottom, yLow=yLow, yHigh=yHigh, x=x, Uncen=Uncen,col=col,lwd=lwd) if (!tinyPlot) mtext(title2,side=3,line=-1.5) - + invisible(eList) } diff --git a/R/plotFluxPred.R b/R/plotFluxPred.R index e39c8e9a..30e63335 100644 --- a/R/plotFluxPred.R +++ b/R/plotFluxPred.R @@ -20,6 +20,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @export @@ -30,12 +31,13 @@ #' plotFluxPred(eList) #' plotFluxPred(eList, fluxUnit = 'poundsDay') #' plotFluxPred(eList, logScale=TRUE) +#' plotFluxPred(eList, logScale=TRUE, rResid=TRUE) #' # Graphs consisting of Jun-Aug #' eList <- setPA(eList, paStart=6,paLong=3) #' plotFluxPred(eList) plotFluxPred<-function(eList, fluxUnit = 3, fluxMax = NA, printTitle = TRUE, oneToOneLine=TRUE, customPar=FALSE,col="black", lwd=1, - cex=0.8, cex.axis=1.1,cex.main=1.1,tinyPlot=FALSE,logScale=FALSE,...){ + cex=0.8, cex.axis=1.1,cex.main=1.1,tinyPlot=FALSE,logScale=FALSE,rResid=FALSE,...){ # this function shows observed versus estimated flux # estimated flux on the x-axis (these include the bias correction), # observed flux on y-axis @@ -79,18 +81,15 @@ plotFluxPred<-function(eList, fluxUnit = 3, fluxMax = NA, fluxFactor <- fluxUnit@unitFactor*86.40 x<-localSample$ConcHat*localSample$Q*fluxFactor - yLow<-localSample$ConcLow*localSample$Q*fluxFactor - yHigh<-localSample$ConcHigh*localSample$Q*fluxFactor + Uncen<-localSample$Uncen if (tinyPlot) { xLab <- fluxUnit@unitEstimateTiny -# yLab <- paste("Obs.", fluxUnit@unitExpressTiny) yLab <- substitute(a ~ b, list(a="Obs.",b= fluxUnit@unitExpressTiny[[1]])) } else { xLab <- fluxUnit@unitEstimate yLab <- substitute(a ~ b, list(a="Observed",b= fluxUnit@unitExpress[[1]])) -# yLab <- paste("Observed", fluxUnit@unitExpress) } if(logScale){ @@ -104,22 +103,42 @@ plotFluxPred<-function(eList, fluxUnit = 3, fluxMax = NA, } plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Observed vs Estimated Flux") else "" - - ############################### - xInfo <- generalAxis(x=x, minVal=minX, maxVal=NA, logScale=logScale, tinyPlot=tinyPlot,padPercent=5) - yInfo <- generalAxis(x=yHigh, minVal=minY, maxVal=fluxMax, logScale=logScale, tinyPlot=tinyPlot,padPercent=5) - - genericEGRETDotPlot(x=x, y=yHigh, - xTicks=xInfo$ticks, yTicks=yInfo$ticks, - xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), - xlab=xLab, ylab=yLab,log=logText, customPar=customPar, - plotTitle=plotTitle,oneToOneLine=oneToOneLine, cex=cex,col=col, - tinyPlot=tinyPlot,cex.axis=cex.axis,cex.main=cex.main,... - ) + + if(!rResid){ + yLow<-localSample$ConcLow*localSample$Q*fluxFactor + yHigh<-localSample$ConcHigh*localSample$Q*fluxFactor + + yInfo <- generalAxis(x=yHigh, minVal=minY, maxVal=fluxMax, logScale=logScale, tinyPlot=tinyPlot,padPercent=5) + + genericEGRETDotPlot(x=x, y=yHigh, + xTicks=xInfo$ticks, yTicks=yInfo$ticks, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yLab,log=logText, customPar=customPar, + plotTitle=plotTitle,oneToOneLine=oneToOneLine, cex=cex,col=col, + tinyPlot=tinyPlot,cex.axis=cex.axis,cex.main=cex.main,... + ) + + censoredSegments(yBottom=yInfo$bottom, yLow=yLow, yHigh=yHigh, x=x, Uncen=Uncen,col=col,lwd=lwd) + } else { + if(!("rObserved" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + yHigh <- localSample$rObserved*localSample$Q*fluxFactor + yInfo <- generalAxis(x=yHigh, minVal=minY, maxVal=fluxMax, logScale=logScale, tinyPlot=tinyPlot,padPercent=5) + + genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1], + xTicks=xInfo$ticks, yTicks=yInfo$ticks, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yLab,log=logText, customPar=customPar, + plotTitle=plotTitle,oneToOneLine=oneToOneLine, cex=cex,col=col, + tinyPlot=tinyPlot,cex.axis=cex.axis,cex.main=cex.main,... + ) + points(x=x[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col) + } - censoredSegments(yBottom=yInfo$bottom, yLow=yLow, yHigh=yHigh, x=x, Uncen=Uncen,col=col,lwd=lwd) if (!tinyPlot) mtext(title2,side=3,line=-1.5) - + invisible(eList) } \ No newline at end of file diff --git a/R/plotResidPred.R b/R/plotResidPred.R index 41819c60..6c0579da 100644 --- a/R/plotResidPred.R +++ b/R/plotResidPred.R @@ -22,6 +22,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot censored residuals as segments, or randomized points. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords water-quality statistics graphics #' @export @@ -30,12 +31,13 @@ #' eList <- Choptank_eList #' # Water year: #' plotResidPred(eList) +#' plotResidPred(eList, rResid=TRUE) #' # Graphs consisting of Jun-Aug #' eList <- setPA(eList, paStart=6,paLong=3) #' plotResidPred(eList) plotResidPred<-function(eList, stdResid = FALSE, tinyPlot = FALSE, printTitle = TRUE, col="black",lwd=1, - cex=0.8, cex.axis=1.1,cex.main=1.1, customPar=FALSE,...){ + cex=0.8, cex.axis=1.1,cex.main=1.1, customPar=FALSE,rResid=FALSE,...){ # this function shows residual versus estimated in log space # estimated log concentration on the x-axis (these are prior to bias correction), # observed log concentration on y-axis @@ -59,10 +61,8 @@ plotResidPred<-function(eList, stdResid = FALSE, title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) x<-exp(localSample$yHat) - yLow<-log(localSample$ConcLow)-localSample$yHat - yHigh<-log(localSample$ConcHigh)-localSample$yHat - yLow<-if(stdResid) yLow/localSample$SE else yLow - yHigh<-if(stdResid) yHigh/localSample$SE else yHigh + xInfo <- generalAxis(x=log(x), minVal=NA, maxVal=NA, tinyPlot=tinyPlot) + Uncen<-localSample$Uncen if (tinyPlot){ @@ -76,17 +76,50 @@ plotResidPred<-function(eList, stdResid = FALSE, #################### - xInfo <- generalAxis(x=log(x), minVal=NA, maxVal=NA, tinyPlot=tinyPlot) - yInfo <- generalAxis(x=yHigh, minVal=NA, maxVal=NA, tinyPlot=tinyPlot) + if(!rResid){ + + yLow<-log(localSample$ConcLow)-localSample$yHat + yHigh<-log(localSample$ConcHigh)-localSample$yHat + yLow<-if(stdResid) yLow/localSample$SE else yLow + yHigh<-if(stdResid) yHigh/localSample$SE else yHigh + + yInfo <- generalAxis(x=yHigh, minVal=NA, maxVal=NA, tinyPlot=tinyPlot) + + genericEGRETDotPlot(x=log(x), y=yHigh, + xTicks=xInfo$ticks, yTicks=yInfo$ticks,col=col, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yLab, plotTitle=plotTitle, customPar=customPar,cex=cex, + hLine=TRUE,cex.axis=cex.axis,cex.main=cex.main, tinyPlot=tinyPlot,... + ) - genericEGRETDotPlot(x=log(x), y=yHigh, - xTicks=xInfo$ticks, yTicks=yInfo$ticks,col=col, - xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), - xlab=xLab, ylab=yLab, plotTitle=plotTitle, customPar=customPar,cex=cex, - hLine=TRUE,cex.axis=cex.axis,cex.main=cex.main, tinyPlot=tinyPlot,... + censoredSegments(yInfo$bottom, yLow, yHigh, log(x), Uncen, col=col, lwd=lwd ) + + } else { + if(!("rResid" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + + yHigh <- localSample$rResid + + if(stdResid){ + yHigh <- yHigh/localSample$SE + } + + yInfo <- generalAxis(x=yHigh, minVal=NA, maxVal=NA, tinyPlot=tinyPlot) + + genericEGRETDotPlot(x=log(x[Uncen == 1]), y=yHigh[Uncen == 1], + xTicks=xInfo$ticks, yTicks=yInfo$ticks,col=col, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yLab, plotTitle=plotTitle, customPar=customPar,cex=cex, + hLine=TRUE,cex.axis=cex.axis,cex.main=cex.main, tinyPlot=tinyPlot,... ) - - censoredSegments(yInfo$bottom, yLow, yHigh, log(x), Uncen, col=col, lwd=lwd ) + points(x=log(x[Uncen == 0]), y=yHigh[Uncen == 0], pch=1,cex=cex,col=col) + + } + if (!tinyPlot) mtext(title2,side=3,line=-1.5) + + invisible(eList) } diff --git a/R/plotResidQ.R b/R/plotResidQ.R index b946deff..527f8e57 100644 --- a/R/plotResidQ.R +++ b/R/plotResidQ.R @@ -23,6 +23,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot censored residuals as segments, or randomized points. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @export @@ -36,7 +37,7 @@ #' plotResidQ(eList) plotResidQ<-function (eList, qUnit = 2, tinyPlot = FALSE, stdResid = FALSE, printTitle = TRUE,col="black",lwd=1, - cex=0.8, cex.axis=1.1,cex.main=1.1,rmSciX=FALSE, customPar=FALSE,...){ + cex=0.8, cex.axis=1.1,cex.main=1.1,rmSciX=FALSE, customPar=FALSE,rResid=FALSE,...){ localINFO <- getInfo(eList) localSample <- getSample(eList) @@ -62,21 +63,6 @@ plotResidQ<-function (eList, qUnit = 2, qFactor <- qUnit@qUnitFactor x <- localSample$Q * qFactor - yLow <- log(localSample$ConcLow) - localSample$yHat - yHigh <- log(localSample$ConcHigh) - localSample$yHat - - yLow <- if(stdResid){ - yLow/localSample$SE - } else { - yLow - } - - yHigh <- if(stdResid){ - yHigh/localSample$SE - } else { - yHigh - } - Uncen <- localSample$Uncen if (tinyPlot){ @@ -92,19 +78,55 @@ plotResidQ<-function (eList, qUnit = 2, ####################### - xInfo <- generalAxis(x=x, minVal=NA, maxVal=NA, logScale=TRUE, tinyPlot=tinyPlot,padPercent=5) - # yInfo <- generalAxis(x=yHigh, minVal=(min(yLow, na.rm = TRUE) - 0.5), maxVal=(max(yHigh) + 0.1), tinyPlot=tinyPlot) - yInfo <- generalAxis(x=yHigh, minVal=NA, maxVal=NA, tinyPlot=tinyPlot,padPercent=5) - - genericEGRETDotPlot(x=x, y=yHigh, - xTicks=xInfo$ticks, yTicks=yInfo$ticks,hLine=TRUE, - xlim = c(xInfo$bottom, xInfo$top), ylim = c(yInfo$bottom, yInfo$top), - xlab = xLab, ylab = yLab, plotTitle=plotTitle,cex=cex, - log = "x", cex.axis=cex.axis,cex.main=cex.main, col=col, - tinyPlot=tinyPlot,rmSciX=rmSciX, customPar=customPar,... - ) + xInfo <- generalAxis(x=x, minVal=NA, maxVal=NA, logScale=TRUE, tinyPlot=tinyPlot,padPercent=5) + + if(!rResid){ + + yLow <- log(localSample$ConcLow) - localSample$yHat + yHigh <- log(localSample$ConcHigh) - localSample$yHat + + if(stdResid){ + yLow <- yLow/localSample$SE + yHigh <- yHigh/localSample$SE + } + + yInfo <- generalAxis(x=yHigh, minVal=NA, maxVal=NA, tinyPlot=tinyPlot,padPercent=5) + + genericEGRETDotPlot(x=x, y=yHigh, + xTicks=xInfo$ticks, yTicks=yInfo$ticks,hLine=TRUE, + xlim = c(xInfo$bottom, xInfo$top), ylim = c(yInfo$bottom, yInfo$top), + xlab = xLab, ylab = yLab, plotTitle=plotTitle,cex=cex, + log = "x", cex.axis=cex.axis,cex.main=cex.main, col=col, + tinyPlot=tinyPlot,rmSciX=rmSciX, customPar=customPar,... + ) + + censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col, lwd=lwd ) + } else { + + if(!("rResid" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + yHigh <- localSample$rResid + + if(stdResid){ + yHigh <- yHigh/localSample$SE + } + + yInfo <- generalAxis(x=yHigh, minVal=NA, maxVal=NA, tinyPlot=tinyPlot,padPercent=5) + + genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1], + xTicks=xInfo$ticks, yTicks=yInfo$ticks,hLine=TRUE, + xlim = c(xInfo$bottom, xInfo$top), ylim = c(yInfo$bottom, yInfo$top), + xlab = xLab, ylab = yLab, plotTitle=plotTitle,cex=cex, + log = "x", cex.axis=cex.axis,cex.main=cex.main, col=col, + tinyPlot=tinyPlot,rmSciX=rmSciX, customPar=customPar,... + ) + points(x=x[Uncen == 0], y=yHigh[Uncen == 0],cex=cex,col=col) + + } - censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col, lwd=lwd ) if (!tinyPlot) mtext(title2,side=3,line=-1.5) + invisible(eList) } diff --git a/R/plotResidTime.R b/R/plotResidTime.R index 9c2f7018..f3907ecf 100644 --- a/R/plotResidTime.R +++ b/R/plotResidTime.R @@ -22,6 +22,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot censored residuals as segments, or randomized points. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @export @@ -35,15 +36,9 @@ #' plotResidTime(eList) plotResidTime<-function(eList, stdResid = FALSE, printTitle = TRUE, hLine=TRUE, tinyPlot=FALSE,col="black",lwd=1, - cex=0.8, cex.axis=1.1,cex.main=1.1, customPar=FALSE,...){ - # this function shows residual versus Time - # Time on the x-axis , - # residual on y-axis - # these residuals are from a "leave-one-out" cross validation application of WRTDS - # if stdResid=FALSE it just works with the regular residuals - # if stdResid=TRUE it computes the standardized residual which is the residual/Sample$SE - - localINFO <- getInfo(eList) + cex=0.8, cex.axis=1.1,cex.main=1.1, customPar=FALSE,rResid=FALSE,...){ + + localINFO <- getInfo(eList) localSample <- getSample(eList) if(sum(c("paStart","paLong") %in% names(localINFO)) == 2){ @@ -59,10 +54,7 @@ plotResidTime<-function(eList, stdResid = FALSE, title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) x<-localSample$DecYear - yLow<-log(localSample$ConcLow)-localSample$yHat - yHigh<-log(localSample$ConcHigh)-localSample$yHat - yLow<-if(stdResid) yLow/localSample$SE else yLow - yHigh<-if(stdResid) yHigh/localSample$SE else yHigh + Uncen<-localSample$Uncen xMin<-min(x) - 0.2 xMax<-max(x) + 0.2 @@ -75,18 +67,51 @@ plotResidTime<-function(eList, stdResid = FALSE, } plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Residual versus Time") else "" - yInfo <- generalAxis(x=yHigh, maxVal=NA, minVal=NA,padPercent=5, tinyPlot=tinyPlot) -# yInfo <- generalAxis(x=yHigh, maxVal=max(yHigh) + 0.1, minVal=min(yLow,na.rm=TRUE) - 0.5,padPercent=0, tinyPlot=tinyPlot) xInfo <- generalAxis(x=x, maxVal=xMax, minVal=xMin,padPercent=0, tinyPlot=tinyPlot) - ########################## - genericEGRETDotPlot(x=x, y=yHigh, - xTicks=xInfo$ticks, yTicks=yInfo$ticks,col=col, - xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom, yInfo$top), - xlab=xLab, ylab=yLab, plotTitle=plotTitle, customPar=customPar, cex=cex, - cex.axis=cex.axis,cex.main=cex.main, hLine=hLine, tinyPlot=tinyPlot,... - ) - censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col,lwd=lwd) + if(!rResid){ + yLow<-log(localSample$ConcLow)-localSample$yHat + yHigh<-log(localSample$ConcHigh)-localSample$yHat + + if(stdResid){ + yLow <- yLow/localSample$SE + yHigh <- yHigh/localSample$SE + } + + yInfo <- generalAxis(x=yHigh, maxVal=NA, minVal=NA,padPercent=5, tinyPlot=tinyPlot) + + genericEGRETDotPlot(x=x, y=yHigh, + xTicks=xInfo$ticks, yTicks=yInfo$ticks,col=col, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom, yInfo$top), + xlab=xLab, ylab=yLab, plotTitle=plotTitle, customPar=customPar, cex=cex, + cex.axis=cex.axis,cex.main=cex.main, hLine=hLine, tinyPlot=tinyPlot,... + ) + censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col,lwd=lwd) + + } else { + if(!("rResid" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + yHigh <- localSample$rResid + + if(stdResid){ + yHigh <- yHigh/localSample$SE + } + + yInfo <- generalAxis(x=yHigh, maxVal=NA, minVal=NA,padPercent=5, tinyPlot=tinyPlot) + + genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1], + xTicks=xInfo$ticks, yTicks=yInfo$ticks,col=col, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom, yInfo$top), + xlab=xLab, ylab=yLab, plotTitle=plotTitle, customPar=customPar, cex=cex, + cex.axis=cex.axis,cex.main=cex.main, hLine=hLine, tinyPlot=tinyPlot,... + ) + points(x=x[Uncen == 0], y=yHigh[Uncen == 0],cex=cex,col=col) + + } + if (!tinyPlot) mtext(title2,side=3,line=-1.5) + invisible(eList) } \ No newline at end of file diff --git a/man/boxConcThree.Rd b/man/boxConcThree.Rd index ba39cfea..9aa3f30c 100644 --- a/man/boxConcThree.Rd +++ b/man/boxConcThree.Rd @@ -6,7 +6,7 @@ \usage{ boxConcThree(eList, tinyPlot = FALSE, printTitle = TRUE, moreTitle = "WRTDS", customPar = FALSE, font.main = 2, cex = 0.8, - cex.main = 1.1, cex.axis = 1.1, ...) + cex.main = 1.1, cex.axis = 1.1, rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Daily, Sample, and INFO dataframes} @@ -27,6 +27,8 @@ boxConcThree(eList, tinyPlot = FALSE, printTitle = TRUE, \item{cex.axis}{magnification to be used for axis annotation relative to the current setting of cex} +\item{rResid}{logical option to plot randomized residuals.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ diff --git a/man/boxResidMonth.Rd b/man/boxResidMonth.Rd index f9a55750..ecdb1944 100644 --- a/man/boxResidMonth.Rd +++ b/man/boxResidMonth.Rd @@ -6,7 +6,7 @@ \usage{ boxResidMonth(eList, stdResid = FALSE, las = 1, printTitle = TRUE, cex = 0.8, cex.axis = 1.1, cex.main = 1.1, font.main = 2, - tinyPlot = FALSE, customPar = FALSE, ...) + tinyPlot = FALSE, customPar = FALSE, rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -29,6 +29,8 @@ boxResidMonth(eList, stdResid = FALSE, las = 1, printTitle = TRUE, \item{customPar}{logical defaults to FALSE. If TRUE, par() should be set by user before calling this function} +\item{rResid}{logical option to plot randomized residuals.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ diff --git a/man/censoredSegments.Rd b/man/censoredSegments.Rd index ce6071f5..15d40152 100644 --- a/man/censoredSegments.Rd +++ b/man/censoredSegments.Rd @@ -27,7 +27,7 @@ See ?par for complete definitions of most optional input variables. } \examples{ x <- c(1,2,3,4,5,6) -y <- c(1,3,4,3.3,4.4,2) +y <- c(1,3,4,3.3,4.4,7) xlim <- c(min(x)*.75,max(x)*1.25) ylim <- c(0,1.25*max(y)) xlab <- "Date" @@ -41,9 +41,9 @@ genericEGRETDotPlot(x=x, y=y, plotTitle="Test" ) yBottom <- 0 -yLow <- c(NA,3,4,3.3,4.4,2) -yHigh <- c(1,3,4,3.3,4.4,2) -Uncen <- c(0,1,1,1,1,1) +yLow <- c(NA,3,4,3.3,4,7) +yHigh <- c(1,3,4,3.3,5,NA) +Uncen <- c(0,1,1,1,0,0) censoredSegments(yBottom=yBottom,yLow=yLow,yHigh=yHigh,x=x,Uncen=Uncen) } \seealso{ diff --git a/man/fluxBiasMulti.Rd b/man/fluxBiasMulti.Rd index a6bcd7bf..5f88c22f 100644 --- a/man/fluxBiasMulti.Rd +++ b/man/fluxBiasMulti.Rd @@ -6,7 +6,7 @@ \usage{ fluxBiasMulti(eList, qUnit = 2, fluxUnit = 3, moreTitle = "WRTDS", cex = 0.7, cex.axis = 1.1, cex.main = 1.1, col = "black", lwd = 1, - ...) + rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least Sample, Daily, and INFO dataframes} @@ -27,6 +27,8 @@ fluxBiasMulti(eList, qUnit = 2, fluxUnit = 3, moreTitle = "WRTDS", \item{lwd}{number line width} +\item{rResid}{logical option to plot censored residuals as segments, or randomized points.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ @@ -44,6 +46,7 @@ and an INFO dataframe with metadata \examples{ eList <- Choptank_eList fluxBiasMulti(eList) +fluxBiasMulti(eList, rResid=TRUE) # Water year: \dontrun{ pdf("fluxBiasMulti.pdf", height=9, width=8) diff --git a/man/makeAugmentedSample.Rd b/man/makeAugmentedSample.Rd new file mode 100644 index 00000000..49c591f4 --- /dev/null +++ b/man/makeAugmentedSample.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2 (4.1.1): do not edit by hand +% Please edit documentation in R/makeRandomResiduals.R +\name{makeAugmentedSample} +\alias{makeAugmentedSample} +\title{Create Randomized Residuals and Observations} +\usage{ +makeAugmentedSample(eList) +} +\arguments{ +\item{eList}{named list with at least the Daily dataframe} +} +\value{ +eList named list with modified Daily data frame. +} +\description{ +This function is used to add two columns to the Sample data frame: rResid and rObserved. + rResid is the randomized residual value computed in log concentration units, and rObserved + is the randomized 'observed' value of concentration in concentration units. +} +\examples{ +eList <- Choptank_eList +eList <- makeAugmentedSample(eList) +} +\keyword{statistics} +\keyword{water-quality} + diff --git a/man/plotConcPred.Rd b/man/plotConcPred.Rd index 892d526c..37bea2ba 100644 --- a/man/plotConcPred.Rd +++ b/man/plotConcPred.Rd @@ -6,7 +6,7 @@ \usage{ plotConcPred(eList, concMax = NA, logScale = FALSE, printTitle = TRUE, tinyPlot = FALSE, cex = 0.8, cex.axis = 1.1, cex.main = 1.1, - customPar = FALSE, col = "black", lwd = 1, ...) + customPar = FALSE, col = "black", lwd = 1, rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -32,6 +32,8 @@ plotConcPred(eList, concMax = NA, logScale = FALSE, printTitle = TRUE, \item{lwd}{number line width} +\item{rResid}{logical option to plot randomized residuals.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ @@ -45,6 +47,7 @@ eList <- Choptank_eList # Water year: plotConcPred(eList) plotConcPred(eList, logScale=TRUE) +plotConcPred(eList, logScale=TRUE, rResid=TRUE) # Graphs consisting of Jun-Aug eList <- setPA(eList, paStart=6,paLong=3) plotConcPred(eList) diff --git a/man/plotFluxPred.Rd b/man/plotFluxPred.Rd index 2624f69d..0825bfb6 100644 --- a/man/plotFluxPred.Rd +++ b/man/plotFluxPred.Rd @@ -7,7 +7,7 @@ plotFluxPred(eList, fluxUnit = 3, fluxMax = NA, printTitle = TRUE, oneToOneLine = TRUE, customPar = FALSE, col = "black", lwd = 1, cex = 0.8, cex.axis = 1.1, cex.main = 1.1, tinyPlot = FALSE, - logScale = FALSE, ...) + logScale = FALSE, rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -37,6 +37,8 @@ plotFluxPred(eList, fluxUnit = 3, fluxMax = NA, printTitle = TRUE, \item{logScale}{logical if TRUE x and y plotted in log axis} +\item{rResid}{logical option to plot randomized residuals.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ @@ -51,6 +53,7 @@ eList <- Choptank_eList plotFluxPred(eList) plotFluxPred(eList, fluxUnit = 'poundsDay') plotFluxPred(eList, logScale=TRUE) +plotFluxPred(eList, logScale=TRUE, rResid=TRUE) # Graphs consisting of Jun-Aug eList <- setPA(eList, paStart=6,paLong=3) plotFluxPred(eList) diff --git a/man/plotResidPred.Rd b/man/plotResidPred.Rd index e169311a..9f7ffeda 100644 --- a/man/plotResidPred.Rd +++ b/man/plotResidPred.Rd @@ -6,7 +6,8 @@ \usage{ plotResidPred(eList, stdResid = FALSE, tinyPlot = FALSE, printTitle = TRUE, col = "black", lwd = 1, cex = 0.8, - cex.axis = 1.1, cex.main = 1.1, customPar = FALSE, ...) + cex.axis = 1.1, cex.main = 1.1, customPar = FALSE, rResid = FALSE, + ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -30,6 +31,8 @@ plotResidPred(eList, stdResid = FALSE, tinyPlot = FALSE, \item{customPar}{logical defaults to FALSE. If TRUE, par() should be set by user before calling this function (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot.} +\item{rResid}{logical option to plot censored residuals as segments, or randomized points.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ @@ -47,6 +50,7 @@ and an INFO dataframe with metadata. eList <- Choptank_eList # Water year: plotResidPred(eList) +plotResidPred(eList, rResid=TRUE) # Graphs consisting of Jun-Aug eList <- setPA(eList, paStart=6,paLong=3) plotResidPred(eList) diff --git a/man/plotResidQ.Rd b/man/plotResidQ.Rd index 36514777..b6011982 100644 --- a/man/plotResidQ.Rd +++ b/man/plotResidQ.Rd @@ -7,7 +7,7 @@ plotResidQ(eList, qUnit = 2, tinyPlot = FALSE, stdResid = FALSE, printTitle = TRUE, col = "black", lwd = 1, cex = 0.8, cex.axis = 1.1, cex.main = 1.1, rmSciX = FALSE, customPar = FALSE, - ...) + rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -35,6 +35,8 @@ plotResidQ(eList, qUnit = 2, tinyPlot = FALSE, stdResid = FALSE, \item{customPar}{logical defaults to FALSE. If TRUE, par() should be set by user before calling this function (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot.} +\item{rResid}{logical option to plot censored residuals as segments, or randomized points.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ diff --git a/man/plotResidTime.Rd b/man/plotResidTime.Rd index 92f909a5..b57ddbd7 100644 --- a/man/plotResidTime.Rd +++ b/man/plotResidTime.Rd @@ -6,7 +6,7 @@ \usage{ plotResidTime(eList, stdResid = FALSE, printTitle = TRUE, hLine = TRUE, tinyPlot = FALSE, col = "black", lwd = 1, cex = 0.8, cex.axis = 1.1, - cex.main = 1.1, customPar = FALSE, ...) + cex.main = 1.1, customPar = FALSE, rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -32,6 +32,8 @@ plotResidTime(eList, stdResid = FALSE, printTitle = TRUE, hLine = TRUE, \item{customPar}{logical defaults to FALSE. If TRUE, par() should be set by user before calling this function (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot.} +\item{rResid}{logical option to plot censored residuals as segments, or randomized points.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ From bd7a88ac836f58c901917fb6085bba5eec7dc1f0 Mon Sep 17 00:00:00 2001 From: Laura DeCicco Date: Tue, 8 Sep 2015 22:34:39 -0500 Subject: [PATCH 5/5] Adding more residual functions. --- R/multiPlotDataOverview.R | 8 ++++-- R/plotConcQ.R | 52 +++++++++++++++++++++++++---------- R/plotConcTime.R | 51 +++++++++++++++++++++++++--------- R/plotConcTimeDaily.R | 53 ++++++++++++++++++++++++++---------- man/multiPlotDataOverview.Rd | 4 ++- man/plotConcQ.Rd | 4 ++- man/plotConcTime.Rd | 4 ++- man/plotConcTimeDaily.Rd | 6 ++-- 8 files changed, 132 insertions(+), 50 deletions(-) diff --git a/R/multiPlotDataOverview.R b/R/multiPlotDataOverview.R index 76968fe8..cb9d4841 100644 --- a/R/multiPlotDataOverview.R +++ b/R/multiPlotDataOverview.R @@ -13,6 +13,7 @@ #' @param cex.main magnification to be used for main titles relative to the current setting of cex #' @param logScaleConc logical if TRUE y in concentration graphs plotted in log axis. Default is TRUE. #' @param logScaleQ logical if TRUE y in streamflow graphs plotted in log axis. Default is TRUE. +#' @param rResid logical option to plot randomized residuals. #' @keywords graphics water-quality statistics #' @seealso \code{\link{plotConcQ}}, \code{\link{boxConcMonth}}, \code{\link{plotConcTime}}, \code{\link{boxQTwice}} #' @export @@ -24,7 +25,7 @@ #' eList <- setPA(eList, paStart=6,paLong=3) #' multiPlotDataOverview(eList, qUnit=1) multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2, - logScaleConc=TRUE, logScaleQ=TRUE){ + logScaleConc=TRUE, logScaleQ=TRUE,rResid=FALSE){ localINFO <- getInfo(eList) @@ -39,9 +40,10 @@ multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2, title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) par(mfcol=c(2,2),oma=c(0,2.4,4.5,2.4),tcl=0.5) - plotConcQ(eList, qUnit = qUnit, tinyPlot = TRUE, printTitle = FALSE,rmSciX=TRUE,logScale=logScaleConc) + plotConcQ(eList, qUnit = qUnit, tinyPlot = TRUE, printTitle = FALSE, + rmSciX=TRUE,logScale=logScaleConc,rResid=rResid) boxConcMonth(eList, printTitle = FALSE, tinyPlot=TRUE,logScale=logScaleConc) - plotConcTime(eList, printTitle = FALSE, tinyPlot = TRUE,logScale=logScaleConc) + plotConcTime(eList, printTitle = FALSE, tinyPlot = TRUE,logScale=logScaleConc,rResid=rResid) boxQTwice(eList, printTitle = FALSE, qUnit = qUnit, tinyPlot=TRUE,logScale=logScaleQ) title<-paste(localINFO$shortName,"\n",localINFO$paramShortName) diff --git a/R/plotConcQ.R b/R/plotConcQ.R index 791dc780..1e5e8ae2 100644 --- a/R/plotConcQ.R +++ b/R/plotConcQ.R @@ -24,6 +24,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options) #' @keywords graphics water-quality statistics #' @export @@ -38,7 +39,7 @@ #' plotConcQ(eList) plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE, concMax = NA, concMin =NA, printTitle = TRUE, cex=0.8, cex.axis=1.1,cex.main=1.1, - rmSciX=FALSE,rmSciY=FALSE, customPar=FALSE,col="black",lwd=1,...){ + rmSciX=FALSE,rmSciY=FALSE, customPar=FALSE,col="black",lwd=1,rResid=FALSE,...){ # this function shows the sample data, # discharge on x-axis on a log scale, concentration on y-axis @@ -67,8 +68,6 @@ plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE, qFactor<-qUnit@qUnitFactor x<-localSample$Q*qFactor - yLow<-localSample$ConcLow - yHigh<-localSample$ConcHigh Uncen<-localSample$Uncen plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Concentration versus Discharge") else "" @@ -87,19 +86,44 @@ plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE, yMin <- 0 } - yInfo <- generalAxis(x=yHigh, maxVal=concMax, minVal=yMin, tinyPlot=tinyPlot,logScale=logScale,units=localINFO$param.units) xInfo <- generalAxis(x=x, maxVal=NA, minVal=NA, logScale=TRUE, tinyPlot=tinyPlot) - genericEGRETDotPlot(x=x, y=yHigh, - xlim=c(xInfo$bottom, xInfo$top), ylim=c(yInfo$bottom,yInfo$top), - xlab=xLab, ylab=yInfo$label, - xTicks=xInfo$ticks, yTicks=yInfo$ticks, - plotTitle=plotTitle, log=logScaleText,cex.axis=cex.axis,cex=cex, - cex.main=cex.main, tinyPlot=tinyPlot,xaxt="n", - rmSciX=rmSciX,rmSciY=rmSciY,customPar=customPar,col=col,lwd=lwd,... - ) - - censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col,lwd=lwd) + if(!rResid){ + yLow<-localSample$ConcLow + yHigh<-localSample$ConcHigh + + yInfo <- generalAxis(x=yHigh, maxVal=concMax, minVal=yMin, tinyPlot=tinyPlot,logScale=logScale,units=localINFO$param.units) + + genericEGRETDotPlot(x=x, y=yHigh, + xlim=c(xInfo$bottom, xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yInfo$label, + xTicks=xInfo$ticks, yTicks=yInfo$ticks, + plotTitle=plotTitle, log=logScaleText,cex.axis=cex.axis,cex=cex, + cex.main=cex.main, tinyPlot=tinyPlot,xaxt="n", + rmSciX=rmSciX,rmSciY=rmSciY,customPar=customPar,col=col,lwd=lwd,... + ) + + censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col,lwd=lwd) + } else { + if(!("rObserved" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + yHigh <- localSample$rObserved + + yInfo <- generalAxis(x=yHigh, maxVal=concMax, minVal=yMin, tinyPlot=tinyPlot,logScale=logScale,units=localINFO$param.units) + + genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1], + xlim=c(xInfo$bottom, xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab=xLab, ylab=yInfo$label, + xTicks=xInfo$ticks, yTicks=yInfo$ticks, + plotTitle=plotTitle, log=logScaleText,cex.axis=cex.axis,cex=cex, + cex.main=cex.main, tinyPlot=tinyPlot,xaxt="n", + rmSciX=rmSciX,rmSciY=rmSciY,customPar=customPar,col=col,lwd=lwd,... + ) + points(x=x[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col) + + } if (!tinyPlot) mtext(title2,side=3,line=-1.5) } diff --git a/R/plotConcTime.R b/R/plotConcTime.R index afbe08b7..0f3153e1 100644 --- a/R/plotConcTime.R +++ b/R/plotConcTime.R @@ -29,6 +29,7 @@ #' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot. #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width. +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary functions sent to the generic plotting function. See ?par for details on possible parameters. #' @keywords graphics water-quality statistics #' @export @@ -42,7 +43,7 @@ #' plotConcTime(eList, qUnit = 1, qLower = 100, qUpper = 10000) #' plotConcTime(eList, logScale=TRUE) plotConcTime<-function(eList, qUnit = 2, - qLower = NA, qUpper = NA, + qLower = NA, qUpper = NA, rResid=FALSE, tinyPlot = FALSE, concMax = NA, concMin = NA, printTitle = TRUE,logScale=FALSE, cex=0.8, cex.axis=1.1,cex.main=1.1, customPar=FALSE,col="black",lwd=1,...){ @@ -95,8 +96,7 @@ plotConcTime<-function(eList, qUnit = 2, # the next section of code sets up the seasonal part of the plot title title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) - yLow<-subSample$ConcLow - yHigh<-subSample$ConcHigh + Uncen<-subSample$Uncen x<-subSample$DecYear @@ -113,17 +113,42 @@ plotConcTime<-function(eList, qUnit = 2, plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n",title3,sep="") else "" xInfo <- generalAxis(x=x, minVal=min(x), maxVal=max(x), tinyPlot=tinyPlot) - yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale, - tinyPlot=tinyPlot,units=attr(eList, "param.units")) - genericEGRETDotPlot(x=x, y=yHigh, - xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), - xlab="", ylab=yInfo$label, - xTicks=xInfo$ticks, yTicks=yInfo$ticks,cex=cex, - plotTitle=plotTitle, log=logVariable, - cex.axis=cex.axis,cex.main=cex.main,tinyPlot=tinyPlot,col=col,customPar=customPar, ... - ) - censoredSegments(yBottom=yInfo$ticks[1],yLow=yLow,yHigh=yHigh,x=x,Uncen=Uncen,col=col,lwd=lwd) + if(!rResid){ + yLow<-subSample$ConcLow + yHigh<-subSample$ConcHigh + + yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale, + tinyPlot=tinyPlot,units=attr(eList, "param.units")) + + genericEGRETDotPlot(x=x, y=yHigh, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab="", ylab=yInfo$label, + xTicks=xInfo$ticks, yTicks=yInfo$ticks,cex=cex, + plotTitle=plotTitle, log=logVariable, + cex.axis=cex.axis,cex.main=cex.main,tinyPlot=tinyPlot,col=col,customPar=customPar, ... + ) + censoredSegments(yBottom=yInfo$ticks[1],yLow=yLow,yHigh=yHigh,x=x,Uncen=Uncen,col=col,lwd=lwd) + } else { + if(!("rObserved" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + } + yHigh <- localSample$rObserved + + yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale, + tinyPlot=tinyPlot,units=attr(eList, "param.units")) + genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1], + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + xlab="", ylab=yInfo$label, + xTicks=xInfo$ticks, yTicks=yInfo$ticks,cex=cex, + plotTitle=plotTitle, log=logVariable, + cex.axis=cex.axis,cex.main=cex.main,tinyPlot=tinyPlot,col=col,customPar=customPar, ... + ) + points(x=x[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col) + + + } if (!tinyPlot) mtext(title2,side=3,line=-1.5) } diff --git a/R/plotConcTimeDaily.R b/R/plotConcTimeDaily.R index a35553de..b7bc3762 100644 --- a/R/plotConcTimeDaily.R +++ b/R/plotConcTimeDaily.R @@ -26,6 +26,7 @@ #' @param col color of points on plot, see ?par 'Color Specification' #' @param lwd number line width #' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the startYear/endYear as limits if FALSE +#' @param rResid logical option to plot randomized residuals. #' @param \dots arbitrary functions sent to the generic plotting function. See ?par for details on possible parameters #' @keywords graphics water-quality statistics #' @export @@ -39,7 +40,7 @@ #' eList <- setPA(eList, paStart=6,paLong=3) #' plotConcTimeDaily(eList) plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE, - concMax = NA, printTitle = TRUE,cex=0.8, cex.axis=1.1, + concMax = NA, printTitle = TRUE,cex=0.8, cex.axis=1.1,rResid=FALSE, cex.main=1.1, customPar=FALSE,col="black",lwd=1,prettyDate=TRUE,...){ localINFO <- getInfo(eList) @@ -63,14 +64,11 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE, title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong) subSample<-localSample[localSample$DecYear>=startYear & localSample$DecYear<= endYear,] - subDaily<-localDaily[localDaily$DecYear>=startYear & localDaily$DecYear <= endYear,] xSample<-subSample$DecYear xDaily<-subDaily$DecYear - yLow<-subSample$ConcLow - yHigh<-subSample$ConcHigh Uncen<-subSample$Uncen plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Observed and Estimated Concentration versus Time") else "" @@ -81,19 +79,44 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE, xInfo <- generalAxis(x=xSample, minVal=startYear, maxVal=endYear, tinyPlot=tinyPlot,padPercent=0,prettyDate=prettyDate) - yCombined <- c(yHigh,subDaily$ConcDay) - yInfo <- generalAxis(x = yCombined, minVal = yBottom, maxVal = concMax, - tinyPlot = tinyPlot, padPercent = 5,units=localINFO$param.units) + if(!rResid){ + + yLow<-subSample$ConcLow + yHigh<-subSample$ConcHigh + + yCombined <- c(yHigh,subDaily$ConcDay) + yInfo <- generalAxis(x = yCombined, minVal = yBottom, maxVal = concMax, + tinyPlot = tinyPlot, padPercent = 5,units=localINFO$param.units) + + genericEGRETDotPlot(x=xSample, y=yHigh, xTicks=xInfo$ticks, yTicks=yInfo$ticks, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + ylab=yInfo$label,plotTitle=plotTitle,cex.axis=cex.axis,col=col,lwd=lwd,cex=cex, + cex.main=cex.main, tinyPlot=tinyPlot,customPar=customPar, xDate=TRUE,... + ) + + censoredSegments(yInfo$bottom,yLow=yLow,yHigh=yHigh,x=xSample,Uncen=Uncen,col=col,lwd=lwd) + } else { + if(!("rObserved" %in% names(localSample))){ + eList <- makeAugmentedSample(eList) + localSample <- eList$Sample + subSample<-localSample[localSample$DecYear>=startYear & localSample$DecYear<= endYear,] + } + + yHigh <- subSample$rObserved + + yCombined <- c(yHigh,subDaily$ConcDay) + yInfo <- generalAxis(x = yCombined, minVal = yBottom, maxVal = concMax, + tinyPlot = tinyPlot, padPercent = 5,units=localINFO$param.units) + genericEGRETDotPlot(x=xSample[subSample$Uncen == 1], y=yHigh[subSample$Uncen == 1], xTicks=xInfo$ticks, yTicks=yInfo$ticks, + xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), + ylab=yInfo$label,plotTitle=plotTitle,cex.axis=cex.axis,col=col,lwd=lwd,cex=cex, + cex.main=cex.main, tinyPlot=tinyPlot,customPar=customPar, xDate=TRUE,... + ) + points(x=xSample[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col) + + } - genericEGRETDotPlot(x=xSample, y=yHigh, xTicks=xInfo$ticks, yTicks=yInfo$ticks, - xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top), - ylab=yInfo$label,plotTitle=plotTitle,cex.axis=cex.axis,col=col,lwd=lwd,cex=cex, - cex.main=cex.main, tinyPlot=tinyPlot,customPar=customPar, xDate=TRUE,... - ) - lines(x=xDaily, y=subDaily$ConcDay, type="l",col=col,lwd=lwd) - - censoredSegments(yInfo$bottom,yLow=yLow,yHigh=yHigh,x=xSample,Uncen=Uncen,col=col,lwd=lwd) if (!tinyPlot) mtext(title2,side=3,line=-1.5) } \ No newline at end of file diff --git a/man/multiPlotDataOverview.Rd b/man/multiPlotDataOverview.Rd index 37e48111..4204531e 100644 --- a/man/multiPlotDataOverview.Rd +++ b/man/multiPlotDataOverview.Rd @@ -5,7 +5,7 @@ \title{Produces a 4 panel plot that gives an overview of the data set prior to any processing} \usage{ multiPlotDataOverview(eList, qUnit = 2, cex.main = 1.2, - logScaleConc = TRUE, logScaleQ = TRUE) + logScaleConc = TRUE, logScaleQ = TRUE, rResid = FALSE) } \arguments{ \item{eList}{named list with at least Daily, Sample, and INFO dataframes} @@ -17,6 +17,8 @@ multiPlotDataOverview(eList, qUnit = 2, cex.main = 1.2, \item{logScaleConc}{logical if TRUE y in concentration graphs plotted in log axis. Default is TRUE.} \item{logScaleQ}{logical if TRUE y in streamflow graphs plotted in log axis. Default is TRUE.} + +\item{rResid}{logical option to plot randomized residuals.} } \description{ The four plots produced are 1) log concentration versus log discharge, 2) log concentration versus time diff --git a/man/plotConcQ.Rd b/man/plotConcQ.Rd index 219f4ed9..fdf72d30 100644 --- a/man/plotConcQ.Rd +++ b/man/plotConcQ.Rd @@ -7,7 +7,7 @@ plotConcQ(eList, qUnit = 2, tinyPlot = FALSE, logScale = FALSE, concMax = NA, concMin = NA, printTitle = TRUE, cex = 0.8, cex.axis = 1.1, cex.main = 1.1, rmSciX = FALSE, rmSciY = FALSE, - customPar = FALSE, col = "black", lwd = 1, ...) + customPar = FALSE, col = "black", lwd = 1, rResid = FALSE, ...) } \arguments{ \item{eList}{named list with at least the Sample and INFO dataframes} @@ -42,6 +42,8 @@ plotConcQ(eList, qUnit = 2, tinyPlot = FALSE, logScale = FALSE, \item{lwd}{number line width} +\item{rResid}{logical option to plot randomized residuals.} + \item{\dots}{arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)} } \description{ diff --git a/man/plotConcTime.Rd b/man/plotConcTime.Rd index 9ccf12fc..e54107d4 100644 --- a/man/plotConcTime.Rd +++ b/man/plotConcTime.Rd @@ -4,7 +4,7 @@ \alias{plotConcTime} \title{Plot of Observed Concentration versus Time} \usage{ -plotConcTime(eList, qUnit = 2, qLower = NA, qUpper = NA, +plotConcTime(eList, qUnit = 2, qLower = NA, qUpper = NA, rResid = FALSE, tinyPlot = FALSE, concMax = NA, concMin = NA, printTitle = TRUE, logScale = FALSE, cex = 0.8, cex.axis = 1.1, cex.main = 1.1, customPar = FALSE, col = "black", lwd = 1, ...) @@ -18,6 +18,8 @@ plotConcTime(eList, qUnit = 2, qLower = NA, qUpper = NA, \item{qUpper}{numeric the upper bound on values of discharge for selection of data points to be plotted, units are those specified by qUnit, default = NA which is equivalent to an upper bound of infinity} +\item{rResid}{logical option to plot randomized residuals.} + \item{tinyPlot}{logical variable, if TRUE plot is designed to be plotted small as part of a multipart figure, default is FALSE.} \item{concMax}{numeric value for the maximum value to be used on the vertical axis, default is NA (which allows it to be set automatically by the data)} diff --git a/man/plotConcTimeDaily.Rd b/man/plotConcTimeDaily.Rd index 58c0ccc7..ed7ca10e 100644 --- a/man/plotConcTimeDaily.Rd +++ b/man/plotConcTimeDaily.Rd @@ -6,8 +6,8 @@ \usage{ plotConcTimeDaily(eList, startYear = NA, endYear = NA, tinyPlot = FALSE, concMax = NA, printTitle = TRUE, cex = 0.8, cex.axis = 1.1, - cex.main = 1.1, customPar = FALSE, col = "black", lwd = 1, - prettyDate = TRUE, ...) + rResid = FALSE, cex.main = 1.1, customPar = FALSE, col = "black", + lwd = 1, prettyDate = TRUE, ...) } \arguments{ \item{eList}{named list with at least the Daily, Sample, and INFO dataframes} @@ -26,6 +26,8 @@ plotConcTimeDaily(eList, startYear = NA, endYear = NA, tinyPlot = FALSE, \item{cex.axis}{magnification to be used for axis annotation relative to the current setting of cex} +\item{rResid}{logical option to plot randomized residuals.} + \item{cex.main}{magnification to be used for main titles relative to the current setting of cex} \item{customPar}{logical defaults to FALSE. If TRUE, par() should be set by user before calling this function