Skip to content

Commit

Permalink
Merge pull request #80 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
More rResid
  • Loading branch information
ldecicco-USGS committed Apr 20, 2016
2 parents 9a89470 + 4771611 commit bf3a9c6
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 152 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
EGRET 2.5.0
===========
* Added an argument to the concentration and residual plotting functions to randomize the censored values for the plots.
* Minor bug fixes

EGRET 2.3.1
===========
* Removed unnecessary disclaimer.
Expand Down
63 changes: 33 additions & 30 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. Show censored values as randomized.
#' @keywords graphics water-quality statistics
#' @seealso \code{\link{plotConcQ}}, \code{\link{boxConcMonth}}, \code{\link{plotConcTime}}, \code{\link{boxQTwice}}
#' @export
Expand All @@ -23,37 +24,39 @@
#' # Graphs consisting of Jun-Aug
#' eList <- setPA(eList, paStart=6,paLong=3)
#' multiPlotDataOverview(eList, qUnit=1)
multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2,
multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2,rResid=FALSE,
logScaleConc=TRUE, logScaleQ=TRUE){

localINFO <- getInfo(eList)

if(sum(c("paStart","paLong") %in% names(localINFO)) == 2){
paLong <- localINFO$paLong
paStart <- localINFO$paStart
} else {
paLong <- 12
paStart <- 10
}

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)
boxConcMonth(eList, printTitle = FALSE, tinyPlot=TRUE,logScale=logScaleConc)
plotConcTime(eList, printTitle = FALSE, tinyPlot = TRUE,logScale=logScaleConc)
boxQTwice(eList, printTitle = FALSE, qUnit = qUnit, tinyPlot=TRUE,logScale=logScaleQ)
title<-paste(localINFO$shortName,"\n",localINFO$paramShortName)

if("" == title2){
mtext(title,cex=cex.main,outer=TRUE,font=2)
} else {
title <- paste(title, title2, sep="\n")
mtext(title, cex = cex.main*.75, outer = TRUE, font = 2)
multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2,
logScaleConc=TRUE, logScaleQ=TRUE,rResid=FALSE){

localINFO <- getInfo(eList)

if(sum(c("paStart","paLong") %in% names(localINFO)) == 2){
paLong <- localINFO$paLong
paStart <- localINFO$paStart
} else {
paLong <- 12
paStart <- 10
}

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,rResid=rResid)
boxConcMonth(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)

if("" == title2){
mtext(title,cex=cex.main,outer=TRUE,font=2)
} else {
title <- paste(title, title2, sep="\n")
mtext(title, cex = cex.main*.75, outer = TRUE, font = 2)
}

par(mfcol=c(1,1),oma=c(0,0,0,0))
}



par(mfcol=c(1,1),oma=c(0,0,0,0))
}
62 changes: 40 additions & 22 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. Show censored values as randomized.
#' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)
#' @keywords graphics water-quality statistics
#' @export
Expand All @@ -36,12 +37,9 @@
#' # Graphs consisting of Jun-Aug
#' eList <- setPA(eList, paStart=6,paLong=3)
#' plotConcQ(eList)
plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,
plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,rResid=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,...){
# this function shows the sample data,
# discharge on x-axis on a log scale, concentration on y-axis

localINFO <- getInfo(eList)
localSample <- getSample(eList)

Expand All @@ -52,7 +50,7 @@ plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,
paLong <- 12
paStart <- 10
}

localSample <- if(paLong == 12) localSample else selectDays(localSample, paLong,paStart)
title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong)

Expand All @@ -68,7 +66,7 @@ plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,
x<-localSample$Q*qFactor

Uncen<-localSample$Uncen

plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Concentration versus Discharge") else ""

if (tinyPlot){
Expand All @@ -87,22 +85,42 @@ plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,

xInfo <- generalAxis(x=x, maxVal=NA, minVal=NA, logScale=TRUE, tinyPlot=tinyPlot)

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)

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)

}
59 changes: 40 additions & 19 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. Show censored values as randomized.
#' @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 @@ -90,12 +91,12 @@ plotConcTime<-function(eList, qUnit = 2,
qText[4]<-paste("For Discharge between",qLower,"and",qUpper,qUnit@qUnitName)
title3<-qText[codeSum]
subSample<-subSample[subSample$Q>qLowerBound & subSample$Q<qUpperBound,]

subSample <- if(paLong == 12) subSample else selectDays(subSample, paLong,paStart)

# the next section of code sets up the seasonal part of the plot title
title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong)

Uncen<-subSample$Uncen
x<-subSample$DecYear

Expand All @@ -108,26 +109,46 @@ plotConcTime<-function(eList, qUnit = 2,
logVariable <- ""
}
#########################################################

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)

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)

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)

}
60 changes: 41 additions & 19 deletions R/plotConcTimeDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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. Show censored values as randomized.
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the startYear/endYear as limits if FALSE
#' @param \dots arbitrary functions sent to the generic plotting function. See ?par for details on possible parameters
#' @keywords graphics water-quality statistics
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 Down Expand Up @@ -67,9 +68,9 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,

xSample<-subSample$DecYear
xDaily<-subDaily$DecYear

Uncen<-subSample$Uncen

plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Observed and Estimated Concentration versus Time") else ""

###################################
Expand All @@ -78,23 +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)

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)
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,...
)

censoredSegments(yInfo$bottom,yLow=yLow,yHigh=yHigh,x=xSample,Uncen=Uncen,col=col,lwd=lwd)


lines(x=xDaily, y=subDaily$ConcDay, type="l",col=col,lwd=lwd)
if (!tinyPlot) mtext(title2,side=3,line=-1.5)

}
Loading

0 comments on commit bf3a9c6

Please sign in to comment.