Skip to content

Commit

Permalink
Adding more residual functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Sep 9, 2015
1 parent 7562302 commit bd7a88a
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 50 deletions.
8 changes: 5 additions & 3 deletions R/multiPlotDataOverview.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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)

Expand Down
52 changes: 38 additions & 14 deletions R/plotConcQ.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 ""
Expand All @@ -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)

}
51 changes: 38 additions & 13 deletions R/plotConcTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,...){

Expand Down Expand Up @@ -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

Expand All @@ -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)

}
53 changes: 38 additions & 15 deletions R/plotConcTimeDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 ""
Expand All @@ -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)

}
4 changes: 3 additions & 1 deletion man/multiPlotDataOverview.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion man/plotConcQ.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion man/plotConcTime.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand All @@ -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)}
Expand Down
6 changes: 4 additions & 2 deletions man/plotConcTimeDaily.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down

0 comments on commit bd7a88a

Please sign in to comment.