Skip to content

Commit bf3a9c6

Browse files
committed
Merge pull request #80 from ldecicco-USGS/master
More rResid
2 parents 9a89470 + 4771611 commit bf3a9c6

17 files changed

+198
-152
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
EGRET 2.5.0
2+
===========
3+
* Added an argument to the concentration and residual plotting functions to randomize the censored values for the plots.
4+
* Minor bug fixes
5+
16
EGRET 2.3.1
27
===========
38
* Removed unnecessary disclaimer.

R/multiPlotDataOverview.R

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#' @param cex.main magnification to be used for main titles relative to the current setting of cex
1414
#' @param logScaleConc logical if TRUE y in concentration graphs plotted in log axis. Default is TRUE.
1515
#' @param logScaleQ logical if TRUE y in streamflow graphs plotted in log axis. Default is TRUE.
16+
#' @param rResid logical. Show censored values as randomized.
1617
#' @keywords graphics water-quality statistics
1718
#' @seealso \code{\link{plotConcQ}}, \code{\link{boxConcMonth}}, \code{\link{plotConcTime}}, \code{\link{boxQTwice}}
1819
#' @export
@@ -23,37 +24,39 @@
2324
#' # Graphs consisting of Jun-Aug
2425
#' eList <- setPA(eList, paStart=6,paLong=3)
2526
#' multiPlotDataOverview(eList, qUnit=1)
26-
multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2,
27+
multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2,rResid=FALSE,
2728
logScaleConc=TRUE, logScaleQ=TRUE){
2829

29-
localINFO <- getInfo(eList)
30-
31-
if(sum(c("paStart","paLong") %in% names(localINFO)) == 2){
32-
paLong <- localINFO$paLong
33-
paStart <- localINFO$paStart
34-
} else {
35-
paLong <- 12
36-
paStart <- 10
37-
}
38-
39-
title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong)
40-
41-
par(mfcol=c(2,2),oma=c(0,2.4,4.5,2.4),tcl=0.5)
42-
plotConcQ(eList, qUnit = qUnit, tinyPlot = TRUE, printTitle = FALSE,
43-
rmSciX=TRUE,logScale=logScaleConc)
44-
boxConcMonth(eList, printTitle = FALSE, tinyPlot=TRUE,logScale=logScaleConc)
45-
plotConcTime(eList, printTitle = FALSE, tinyPlot = TRUE,logScale=logScaleConc)
46-
boxQTwice(eList, printTitle = FALSE, qUnit = qUnit, tinyPlot=TRUE,logScale=logScaleQ)
47-
title<-paste(localINFO$shortName,"\n",localINFO$paramShortName)
48-
49-
if("" == title2){
50-
mtext(title,cex=cex.main,outer=TRUE,font=2)
51-
} else {
52-
title <- paste(title, title2, sep="\n")
53-
mtext(title, cex = cex.main*.75, outer = TRUE, font = 2)
30+
multiPlotDataOverview<-function (eList, qUnit = 2,cex.main=1.2,
31+
logScaleConc=TRUE, logScaleQ=TRUE,rResid=FALSE){
32+
33+
localINFO <- getInfo(eList)
34+
35+
if(sum(c("paStart","paLong") %in% names(localINFO)) == 2){
36+
paLong <- localINFO$paLong
37+
paStart <- localINFO$paStart
38+
} else {
39+
paLong <- 12
40+
paStart <- 10
41+
}
42+
43+
title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong)
44+
45+
par(mfcol=c(2,2),oma=c(0,2.4,4.5,2.4),tcl=0.5)
46+
plotConcQ(eList, qUnit = qUnit, tinyPlot = TRUE, printTitle = FALSE,
47+
rmSciX=TRUE,logScale=logScaleConc,rResid=rResid)
48+
boxConcMonth(eList, printTitle = FALSE, tinyPlot=TRUE,logScale=logScaleConc)
49+
plotConcTime(eList, printTitle = FALSE, tinyPlot = TRUE,logScale=logScaleConc,rResid=rResid)
50+
boxQTwice(eList, printTitle = FALSE, qUnit = qUnit, tinyPlot=TRUE,logScale=logScaleQ)
51+
title<-paste(localINFO$shortName,"\n",localINFO$paramShortName)
52+
53+
if("" == title2){
54+
mtext(title,cex=cex.main,outer=TRUE,font=2)
55+
} else {
56+
title <- paste(title, title2, sep="\n")
57+
mtext(title, cex = cex.main*.75, outer = TRUE, font = 2)
58+
}
59+
60+
par(mfcol=c(1,1),oma=c(0,0,0,0))
5461
}
55-
56-
57-
58-
par(mfcol=c(1,1),oma=c(0,0,0,0))
5962
}

R/plotConcQ.R

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot.
2525
#' @param col color of points on plot, see ?par 'Color Specification'
2626
#' @param lwd number line width
27+
#' @param rResid logical. Show censored values as randomized.
2728
#' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)
2829
#' @keywords graphics water-quality statistics
2930
#' @export
@@ -36,12 +37,9 @@
3637
#' # Graphs consisting of Jun-Aug
3738
#' eList <- setPA(eList, paStart=6,paLong=3)
3839
#' plotConcQ(eList)
39-
plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,
40+
plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,rResid=FALSE,
4041
concMax = NA, concMin =NA, printTitle = TRUE, cex=0.8, cex.axis=1.1,cex.main=1.1,
4142
rmSciX=FALSE,rmSciY=FALSE, customPar=FALSE,col="black",lwd=1,...){
42-
# this function shows the sample data,
43-
# discharge on x-axis on a log scale, concentration on y-axis
44-
4543
localINFO <- getInfo(eList)
4644
localSample <- getSample(eList)
4745

@@ -52,7 +50,7 @@ plotConcQ<-function(eList, qUnit = 2, tinyPlot = FALSE, logScale=FALSE,
5250
paLong <- 12
5351
paStart <- 10
5452
}
55-
53+
5654
localSample <- if(paLong == 12) localSample else selectDays(localSample, paLong,paStart)
5755
title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong)
5856

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

7068
Uncen<-localSample$Uncen
71-
69+
7270
plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Concentration versus Discharge") else ""
7371

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

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

90-
yLow<-localSample$ConcLow
91-
yHigh<-localSample$ConcHigh
92-
93-
yInfo <- generalAxis(x=yHigh, maxVal=concMax, minVal=yMin, tinyPlot=tinyPlot,logScale=logScale,units=localINFO$param.units)
94-
95-
genericEGRETDotPlot(x=x, y=yHigh,
96-
xlim=c(xInfo$bottom, xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
97-
xlab=xLab, ylab=yInfo$label,
98-
xTicks=xInfo$ticks, yTicks=yInfo$ticks,
99-
plotTitle=plotTitle, log=logScaleText,cex.axis=cex.axis,cex=cex,
100-
cex.main=cex.main, tinyPlot=tinyPlot,xaxt="n",
101-
rmSciX=rmSciX,rmSciY=rmSciY,customPar=customPar,col=col,lwd=lwd,...
102-
)
103-
104-
censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col,lwd=lwd)
105-
88+
if(!rResid){
89+
yLow<-localSample$ConcLow
90+
yHigh<-localSample$ConcHigh
91+
92+
yInfo <- generalAxis(x=yHigh, maxVal=concMax, minVal=yMin, tinyPlot=tinyPlot,logScale=logScale,units=localINFO$param.units)
93+
94+
genericEGRETDotPlot(x=x, y=yHigh,
95+
xlim=c(xInfo$bottom, xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
96+
xlab=xLab, ylab=yInfo$label,
97+
xTicks=xInfo$ticks, yTicks=yInfo$ticks,
98+
plotTitle=plotTitle, log=logScaleText,cex.axis=cex.axis,cex=cex,
99+
cex.main=cex.main, tinyPlot=tinyPlot,xaxt="n",
100+
rmSciX=rmSciX,rmSciY=rmSciY,customPar=customPar,col=col,lwd=lwd,...
101+
)
102+
103+
censoredSegments(yInfo$bottom, yLow, yHigh, x, Uncen,col=col,lwd=lwd)
104+
} else {
105+
if(!("rObserved" %in% names(localSample))){
106+
eList <- makeAugmentedSample(eList)
107+
localSample <- eList$Sample
108+
}
109+
yHigh <- localSample$rObserved
110+
111+
yInfo <- generalAxis(x=yHigh, maxVal=concMax, minVal=yMin, tinyPlot=tinyPlot,logScale=logScale,units=localINFO$param.units)
112+
113+
genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1],
114+
xlim=c(xInfo$bottom, xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
115+
xlab=xLab, ylab=yInfo$label,
116+
xTicks=xInfo$ticks, yTicks=yInfo$ticks,
117+
plotTitle=plotTitle, log=logScaleText,cex.axis=cex.axis,cex=cex,
118+
cex.main=cex.main, tinyPlot=tinyPlot,xaxt="n",
119+
rmSciX=rmSciX,rmSciY=rmSciY,customPar=customPar,col=col,lwd=lwd,...
120+
)
121+
points(x=x[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col)
122+
123+
}
106124
if (!tinyPlot) mtext(title2,side=3,line=-1.5)
107125

108126
}

R/plotConcTime.R

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot.
3030
#' @param col color of points on plot, see ?par 'Color Specification'
3131
#' @param lwd number line width.
32+
#' @param rResid logical. Show censored values as randomized.
3233
#' @param \dots arbitrary functions sent to the generic plotting function. See ?par for details on possible parameters.
3334
#' @keywords graphics water-quality statistics
3435
#' @export
@@ -42,7 +43,7 @@
4243
#' plotConcTime(eList, qUnit = 1, qLower = 100, qUpper = 10000)
4344
#' plotConcTime(eList, logScale=TRUE)
4445
plotConcTime<-function(eList, qUnit = 2,
45-
qLower = NA, qUpper = NA,
46+
qLower = NA, qUpper = NA, rResid=FALSE,
4647
tinyPlot = FALSE, concMax = NA, concMin = NA, printTitle = TRUE,logScale=FALSE,
4748
cex=0.8, cex.axis=1.1,cex.main=1.1, customPar=FALSE,col="black",lwd=1,...){
4849

@@ -90,12 +91,12 @@ plotConcTime<-function(eList, qUnit = 2,
9091
qText[4]<-paste("For Discharge between",qLower,"and",qUpper,qUnit@qUnitName)
9192
title3<-qText[codeSum]
9293
subSample<-subSample[subSample$Q>qLowerBound & subSample$Q<qUpperBound,]
93-
94+
9495
subSample <- if(paLong == 12) subSample else selectDays(subSample, paLong,paStart)
9596

9697
# the next section of code sets up the seasonal part of the plot title
9798
title2<-if(paLong==12) "" else setSeasonLabelByUser(paStartInput=paStart,paLongInput=paLong)
98-
99+
99100
Uncen<-subSample$Uncen
100101
x<-subSample$DecYear
101102

@@ -108,26 +109,46 @@ plotConcTime<-function(eList, qUnit = 2,
108109
logVariable <- ""
109110
}
110111
#########################################################
111-
112+
112113
plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n",title3,sep="") else ""
113114

114115
xInfo <- generalAxis(x=x, minVal=min(x), maxVal=max(x), tinyPlot=tinyPlot)
115116

116-
yLow<-subSample$ConcLow
117-
yHigh<-subSample$ConcHigh
118-
119-
yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale,
120-
tinyPlot=tinyPlot,units=attr(eList, "param.units"))
121-
122-
genericEGRETDotPlot(x=x, y=yHigh,
123-
xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
124-
xlab="", ylab=yInfo$label,
125-
xTicks=xInfo$ticks, yTicks=yInfo$ticks,cex=cex,
126-
plotTitle=plotTitle, log=logVariable,
127-
cex.axis=cex.axis,cex.main=cex.main,tinyPlot=tinyPlot,col=col,customPar=customPar, ...
128-
)
129-
censoredSegments(yBottom=yInfo$ticks[1],yLow=yLow,yHigh=yHigh,x=x,Uncen=Uncen,col=col,lwd=lwd)
130-
117+
if(!rResid){
118+
yLow<-subSample$ConcLow
119+
yHigh<-subSample$ConcHigh
120+
121+
yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale,
122+
tinyPlot=tinyPlot,units=attr(eList, "param.units"))
123+
124+
genericEGRETDotPlot(x=x, y=yHigh,
125+
xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
126+
xlab="", ylab=yInfo$label,
127+
xTicks=xInfo$ticks, yTicks=yInfo$ticks,cex=cex,
128+
plotTitle=plotTitle, log=logVariable,
129+
cex.axis=cex.axis,cex.main=cex.main,tinyPlot=tinyPlot,col=col,customPar=customPar, ...
130+
)
131+
censoredSegments(yBottom=yInfo$ticks[1],yLow=yLow,yHigh=yHigh,x=x,Uncen=Uncen,col=col,lwd=lwd)
132+
} else {
133+
if(!("rObserved" %in% names(localSample))){
134+
eList <- makeAugmentedSample(eList)
135+
localSample <- eList$Sample
136+
}
137+
yHigh <- localSample$rObserved
138+
139+
yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale,
140+
tinyPlot=tinyPlot,units=attr(eList, "param.units"))
141+
genericEGRETDotPlot(x=x[Uncen == 1], y=yHigh[Uncen == 1],
142+
xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
143+
xlab="", ylab=yInfo$label,
144+
xTicks=xInfo$ticks, yTicks=yInfo$ticks,cex=cex,
145+
plotTitle=plotTitle, log=logVariable,
146+
cex.axis=cex.axis,cex.main=cex.main,tinyPlot=tinyPlot,col=col,customPar=customPar, ...
147+
)
148+
points(x=x[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col)
149+
150+
151+
}
131152
if (!tinyPlot) mtext(title2,side=3,line=-1.5)
132153

133154
}

R/plotConcTimeDaily.R

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#' (for example, adjusting margins with par(mar=c(5,5,5,5))). If customPar FALSE, EGRET chooses the best margins depending on tinyPlot.
2626
#' @param col color of points on plot, see ?par 'Color Specification'
2727
#' @param lwd number line width
28+
#' @param rResid logical. Show censored values as randomized.
2829
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the startYear/endYear as limits if FALSE
2930
#' @param \dots arbitrary functions sent to the generic plotting function. See ?par for details on possible parameters
3031
#' @keywords graphics water-quality statistics
@@ -39,7 +40,7 @@
3940
#' eList <- setPA(eList, paStart=6,paLong=3)
4041
#' plotConcTimeDaily(eList)
4142
plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,
42-
concMax = NA, printTitle = TRUE,cex=0.8, cex.axis=1.1,
43+
concMax = NA, printTitle = TRUE,cex=0.8, cex.axis=1.1,rResid=FALSE,
4344
cex.main=1.1, customPar=FALSE,col="black",lwd=1,prettyDate=TRUE,...){
4445

4546
localINFO <- getInfo(eList)
@@ -67,9 +68,9 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,
6768

6869
xSample<-subSample$DecYear
6970
xDaily<-subDaily$DecYear
70-
71+
7172
Uncen<-subSample$Uncen
72-
73+
7374
plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n","Observed and Estimated Concentration versus Time") else ""
7475

7576
###################################
@@ -78,23 +79,44 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,
7879

7980
xInfo <- generalAxis(x=xSample, minVal=startYear, maxVal=endYear, tinyPlot=tinyPlot,padPercent=0,prettyDate=prettyDate)
8081

81-
yLow<-subSample$ConcLow
82-
yHigh<-subSample$ConcHigh
83-
84-
yCombined <- c(yHigh,subDaily$ConcDay)
85-
yInfo <- generalAxis(x = yCombined, minVal = yBottom, maxVal = concMax,
86-
tinyPlot = tinyPlot, padPercent = 5,units=localINFO$param.units)
82+
if(!rResid){
83+
84+
yLow<-subSample$ConcLow
85+
yHigh<-subSample$ConcHigh
86+
87+
yCombined <- c(yHigh,subDaily$ConcDay)
88+
yInfo <- generalAxis(x = yCombined, minVal = yBottom, maxVal = concMax,
89+
tinyPlot = tinyPlot, padPercent = 5,units=localINFO$param.units)
90+
91+
genericEGRETDotPlot(x=xSample, y=yHigh, xTicks=xInfo$ticks, yTicks=yInfo$ticks,
92+
xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
93+
ylab=yInfo$label,plotTitle=plotTitle,cex.axis=cex.axis,col=col,lwd=lwd,cex=cex,
94+
cex.main=cex.main, tinyPlot=tinyPlot,customPar=customPar, xDate=TRUE,...
95+
)
96+
97+
censoredSegments(yInfo$bottom,yLow=yLow,yHigh=yHigh,x=xSample,Uncen=Uncen,col=col,lwd=lwd)
98+
} else {
99+
if(!("rObserved" %in% names(localSample))){
100+
eList <- makeAugmentedSample(eList)
101+
localSample <- eList$Sample
102+
subSample<-localSample[localSample$DecYear>=startYear & localSample$DecYear<= endYear,]
103+
}
104+
105+
yHigh <- subSample$rObserved
106+
107+
yCombined <- c(yHigh,subDaily$ConcDay)
108+
yInfo <- generalAxis(x = yCombined, minVal = yBottom, maxVal = concMax,
109+
tinyPlot = tinyPlot, padPercent = 5,units=localINFO$param.units)
110+
genericEGRETDotPlot(x=xSample[subSample$Uncen == 1], y=yHigh[subSample$Uncen == 1], xTicks=xInfo$ticks, yTicks=yInfo$ticks,
111+
xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
112+
ylab=yInfo$label,plotTitle=plotTitle,cex.axis=cex.axis,col=col,lwd=lwd,cex=cex,
113+
cex.main=cex.main, tinyPlot=tinyPlot,customPar=customPar, xDate=TRUE,...
114+
)
115+
points(x=xSample[Uncen == 0], y=yHigh[Uncen == 0], pch=1,cex=cex,col=col)
116+
117+
}
87118

88-
genericEGRETDotPlot(x=xSample, y=yHigh, xTicks=xInfo$ticks, yTicks=yInfo$ticks,
89-
xlim=c(xInfo$bottom,xInfo$top), ylim=c(yInfo$bottom,yInfo$top),
90-
ylab=yInfo$label,plotTitle=plotTitle,cex.axis=cex.axis,col=col,lwd=lwd,cex=cex,
91-
cex.main=cex.main, tinyPlot=tinyPlot,customPar=customPar, xDate=TRUE,...
92-
)
93-
94-
censoredSegments(yInfo$bottom,yLow=yLow,yHigh=yHigh,x=xSample,Uncen=Uncen,col=col,lwd=lwd)
95-
96-
97119
lines(x=xDaily, y=subDaily$ConcDay, type="l",col=col,lwd=lwd)
98120
if (!tinyPlot) mtext(title2,side=3,line=-1.5)
99-
121+
100122
}

0 commit comments

Comments
 (0)