Skip to content

Commit

Permalink
Merge pull request #91 from ldecicco-USGS/master
Browse files Browse the repository at this point in the history
start/end arguments
  • Loading branch information
ldecicco-USGS authored Jul 15, 2016
2 parents 7002524 + 1ae3475 commit c19c23d
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 64 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: EGRET
Type: Package
Title: Exploration and Graphics for RivEr Trends (EGRET)
Version: 2.5.3
Version: 2.6.0
Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "[email protected]"),
person("Laura", "DeCicco", role = c("aut","cre"),
Expand All @@ -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: 2016-06-21
Date: 2016-07-15
Depends:
R (>= 3.0)
Imports:
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
EGRET 2.6.0
===========
* start/end year argument names unified to yearStart and yearEnd (previously included startYear and endYear)

EGRET 2.5.3
===========
* Argument for randomized censored values names randomCensored
Expand Down
2 changes: 1 addition & 1 deletion R/generalAxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param padPercent number used to pad the max and min if not specified
#' @param concentration logical if concentration=TRUE, labels returned as concentration units, otherwise flux units.
#' @param units character concentration units. Typically found in INFO$param.units.
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the startYear/endYear as limits if FALSE
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the yearStart/yearEnd as limits if FALSE
#' @keywords graphics water-quality statistics
#' @export
#' @examples
Expand Down
16 changes: 12 additions & 4 deletions R/plotConcTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' @param qUnit object of qUnit class \code{\link{printqUnitCheatSheet}}, or numeric represented the short code, or character representing the descriptive name.
#' @param qLower numeric the lower bound on values of discharge used to select the data points to be plotted, units are those specified by qUnit, default = NA which is equivalent to a lower bound of zero but if the desired lower bound is zero use qLower = NA
#' @param 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
#' @param yearStart numeric is the calendar year containing the first estimated annual value to be plotted, default is NA (which allows it to be set automatically by the data)
#' @param yearEnd numeric is the calendar year just after the last estimated annual value to be plotted, default is NA (which allows it to be set automatically by the data)
#' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multipart figure, default is FALSE.
#' @param 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)
#' @param concMin numeric value for lower limit on concentration shown on the vertical log graph, default is NA
Expand Down Expand Up @@ -43,7 +45,7 @@
#' plotConcTime(eList, qUnit = 1, qLower = 100, qUpper = 10000)
#' plotConcTime(eList, logScale=TRUE)
#' plotConcTime(eList, qUnit = 1, qLower = 100, qUpper = 10000, randomCensored = TRUE)
plotConcTime<-function(eList, qUnit = 2,
plotConcTime<-function(eList, qUnit = 2, yearStart = NA, yearEnd = NA,
qLower = NA, qUpper = NA, randomCensored=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 @@ -107,14 +109,16 @@ plotConcTime<-function(eList, qUnit = 2,

plotTitle<-if(printTitle) paste(localINFO$shortName,"\n",localINFO$paramShortName,"\n",title3,sep="") else ""


if(!randomCensored){
subSample<-subSample[subSample$Q>qLowerBound & subSample$Q<qUpperBound,]
subSample <- if(paLong == 12) subSample else selectDays(subSample, paLong,paStart)
Uncen<-subSample$Uncen
x<-subSample$DecYear

xInfo <- generalAxis(x=x, minVal=min(x), maxVal=max(x), tinyPlot=tinyPlot)
xInfo <- generalAxis(x=x,
minVal = ifelse(is.na(yearStart),min(x),yearStart),
maxVal=ifelse(is.na(yearEnd),max(x),yearEnd),
tinyPlot=tinyPlot)

yLow<-subSample$ConcLow
yHigh<-subSample$ConcHigh
Expand Down Expand Up @@ -144,8 +148,12 @@ plotConcTime<-function(eList, qUnit = 2,

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

xInfo <- generalAxis(x=x,
minVal = ifelse(is.na(yearStart),min(x),yearStart),
maxVal=ifelse(is.na(yearEnd),max(x),yearEnd),
tinyPlot=tinyPlot)

xInfo <- generalAxis(x=x, minVal=min(x), maxVal=max(x), tinyPlot=tinyPlot)
yHigh <- subSample$rObserved
yInfo <- generalAxis(x=yHigh, minVal=minYLow, maxVal=concMax, logScale=logScale,
tinyPlot=tinyPlot,units=attr(eList, "param.units"))
Expand Down
22 changes: 11 additions & 11 deletions R/plotConcTimeDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#' a Daily dataframe with the daily flow data,
#' and an INFO dataframe with metadata.
#'
#' @param startYear numeric specifying the starting date (expressed as decimal years, for example 1989.0) for the plot
#' @param endYear numeric specifiying the ending date for the plot
#' @param yearStart numeric specifying the starting date (expressed as decimal years, for example 1989.0) for the plot
#' @param yearEnd numeric specifiying the ending date for the plot
#' @param eList named list with at least the Daily, Sample, and INFO dataframes
#' @param tinyPlot logical variable, if TRUE plot is designed to be short and wide, default is FALSE.
#' @param concMax number specifying the maximum value to be used on the vertical axis, default is NA (which allows it to be set automatically by the data)
Expand All @@ -26,7 +26,7 @@
#' @param col color of points on plot, see ?par 'Color Specification'
#' @param lwd number line width
#' @param randomCensored 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 prettyDate logical use 'pretty' limits for date axis if TRUE, or force the yearStart/yearEnd 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
#' @export
Expand All @@ -35,20 +35,20 @@
#' eList <- Choptank_eList
#' # Water year:
#' plotConcTimeDaily(eList)
#' plotConcTimeDaily(eList, startYear=1998,endYear=2001)
#' plotConcTimeDaily(eList, yearStart=1998,yearEnd=2001)
#' # Graphs consisting of Jun-Aug
#' eList <- setPA(eList, paStart=6,paLong=3)
#' plotConcTimeDaily(eList)
plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,
plotConcTimeDaily<-function(eList, yearStart=NA, yearEnd=NA, tinyPlot = FALSE,
concMax = NA, printTitle = TRUE,cex=0.8, cex.axis=1.1,randomCensored=FALSE,
cex.main=1.1, customPar=FALSE,col="black",lwd=1,prettyDate=TRUE,...){

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

startYear <- if (is.na(startYear)) as.integer(min(localSample$DecYear,na.rm=TRUE)) else startYear
endYear <- if (is.na(endYear)) as.integer(max(localSample$DecYear,na.rm=TRUE)) else endYear
yearStart <- if (is.na(yearStart)) as.integer(min(localSample$DecYear,na.rm=TRUE)) else yearStart
yearEnd <- if (is.na(yearEnd)) as.integer(max(localSample$DecYear,na.rm=TRUE)) else yearEnd

if(sum(c("paStart","paLong") %in% names(localINFO)) == 2){
paLong <- localINFO$paLong
Expand All @@ -63,8 +63,8 @@ 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,]
subSample<-localSample[localSample$DecYear>=yearStart & localSample$DecYear<= yearEnd,]
subDaily<-localDaily[localDaily$DecYear>=yearStart & localDaily$DecYear <= yearEnd,]

xSample<-subSample$DecYear
xDaily<-subDaily$DecYear
Expand All @@ -77,7 +77,7 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,

yBottom <- 0 #Not specified within script, added under assumption that it's always zero based on ylim definition in this function

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

if(!randomCensored){

Expand All @@ -99,7 +99,7 @@ plotConcTimeDaily<-function(eList, startYear=NA, endYear=NA, tinyPlot = FALSE,
if(!("rObserved" %in% names(localSample))){
eList <- makeAugmentedSample(eList)
localSample <- eList$Sample
subSample<-localSample[localSample$DecYear>=startYear & localSample$DecYear<= endYear,]
subSample<-localSample[localSample$DecYear>=yearStart & localSample$DecYear<= yearEnd,]
}

yHigh <- subSample$rObserved
Expand Down
18 changes: 9 additions & 9 deletions R/plotFluxTimeDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#' and an INFO dataframe with metadata.
#'
#' @param eList named list with at least the Daily, Sample, and INFO dataframes
#' @param startYear numeric specifying the starting date (expressed as decimal years, for example 1989.0) for the plot
#' @param endYear numeric specifiying the ending date for the plot
#' @param yearStart numeric specifying the starting date (expressed as decimal years, for example 1989.0) for the plot
#' @param yearEnd numeric specifiying the ending date for the plot
#' @param tinyPlot logical variable, if TRUE plot is designed to be short and wide, default is FALSE.
#' @param fluxUnit number representing in pre-defined fluxUnit class array. \code{\link{printFluxUnitCheatSheet}}
#' @param fluxMax number specifying the maximum value to be used on the vertical axis, default is NA (which allows it to be set automatically by the data)
Expand All @@ -24,7 +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 prettyDate logical use 'pretty' limits for date axis if TRUE, or force the startYear/endYear as limits if FALSE
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the yearStart/yearEnd as limits if FALSE
#' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)
#' @keywords graphics water-quality statistics
#' @export
Expand All @@ -37,7 +37,7 @@
#' # Graphs consisting of Jun-Aug
#' eList <- setPA(eList, paStart=6,paLong=3)
#' plotFluxTimeDaily(eList)
plotFluxTimeDaily<-function (eList, startYear=NA, endYear=NA,
plotFluxTimeDaily<-function (eList, yearStart=NA, yearEnd=NA,
tinyPlot = FALSE, fluxUnit = 3, fluxMax = NA,
printTitle = TRUE, cex=0.8, cex.axis=1.1,cex.main=1.1,
customPar=FALSE,col="black",lwd=1,prettyDate=TRUE,...) {
Expand Down Expand Up @@ -82,12 +82,12 @@ plotFluxTimeDaily<-function (eList, startYear=NA, endYear=NA,

fluxFactor <- fluxUnit@unitFactor*86.40

startYear <- if (is.na(startYear)) as.integer(min(localSample$DecYear,na.rm=TRUE)) else startYear
endYear <- if (is.na(endYear)) as.integer(max(localSample$DecYear,na.rm=TRUE)) else endYear
yearStart <- if (is.na(yearStart)) as.integer(min(localSample$DecYear,na.rm=TRUE)) else yearStart
yearEnd <- if (is.na(yearEnd)) as.integer(max(localSample$DecYear,na.rm=TRUE)) else yearEnd

subSample <- localSample[localSample$DecYear >= startYear & localSample$DecYear <= endYear,]
subSample <- localSample[localSample$DecYear >= yearStart & localSample$DecYear <= yearEnd,]

subDaily <- localDaily[localDaily$DecYear >= startYear & localDaily$DecYear <= endYear,]
subDaily <- localDaily[localDaily$DecYear >= yearStart & localDaily$DecYear <= yearEnd,]

xSample <- subSample$DecYear
xDaily <- subDaily$DecYear
Expand All @@ -107,7 +107,7 @@ plotFluxTimeDaily<-function (eList, startYear=NA, endYear=NA,

yBottom <- 0

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

yCombined <- c(yHigh,subDaily$ConcDay*subDaily$Q*fluxFactor)
Expand Down
18 changes: 9 additions & 9 deletions R/plotQTimeDaily.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' and an INFO dataframe with metadata.
#'
#' @param eList named list with at least the Daily and INFO dataframes
#' @param startYear numeric indicating the starting year for the graph
#' @param endYear numeric indicating the ending year for the graph (should be a time in decimal years that is after the last observations to be plotted)
#' @param yearStart numeric indicating the starting year for the graph
#' @param yearEnd numeric indicating the ending year for the graph (should be a time in decimal years that is after the last observations to be plotted)
#' @param qLower numeric specifying the lower bound on discharges that are to be plotted, must be in the units specified by qUnit, default is NA (lower bound is zero)
#' @param qUnit object of qUnit class. \code{\link{printqUnitCheatSheet}}, or numeric represented the short code, or character representing the descriptive name. Default is qUnit=1 (cubic feet per second)
#' @param tinyPlot logical variable, if TRUE plot is designed to be short and wide, default is FALSE.
Expand All @@ -23,7 +23,7 @@
#' @param 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.
#' @param logScale logical whether or not to use a log scale in the y axis. Default is FALSE.
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the startYear/endYear as limits if FALSE
#' @param prettyDate logical use 'pretty' limits for date axis if TRUE, or force the yearStart/yearEnd as limits if FALSE
#' @param \dots arbitrary graphical parameters that will be passed to genericEGRETDotPlot function (see ?par for options)
#' @keywords graphics streamflow
#' @export
Expand All @@ -32,12 +32,12 @@
#' eList <- Choptank_eList
#' # Water year:
#' plotQTimeDaily(eList)
#' plotQTimeDaily(eList, startYear=1990, endYear=2000,qLower=1500)
#' plotQTimeDaily(eList, yearStart=1990, yearEnd=2000,qLower=1500)
#' plotQTimeDaily(eList, prettyDate=FALSE)
#' # Graphs consisting of Jun-Aug
#' eList <- setPA(eList, paStart=6,paLong=3)
#' plotQTimeDaily(eList)
plotQTimeDaily<-function (eList, startYear=NA, endYear=NA, qLower = NA, qUnit = 1, logScale=FALSE,
plotQTimeDaily<-function (eList, yearStart=NA, yearEnd=NA, qLower = NA, qUnit = 1, logScale=FALSE,
tinyPlot = FALSE, printTitle = TRUE, lwd = 3, col="red",
cex.main = 1.2, cex.lab = 1.2, customPar=FALSE,prettyDate=TRUE,...){

Expand Down Expand Up @@ -76,10 +76,10 @@ plotQTimeDaily<-function (eList, startYear=NA, endYear=NA, qLower = NA, qUnit =
yLab <- qUnit@qUnitExpress
}

startYear <- if (is.na(startYear)) as.integer(min(localDaily$DecYear,na.rm=TRUE)) else startYear
endYear <- if (is.na(endYear)) as.integer(max(localDaily$DecYear,na.rm=TRUE)) else endYear
yearStart <- if (is.na(yearStart)) as.integer(min(localDaily$DecYear,na.rm=TRUE)) else yearStart
yearEnd <- if (is.na(yearEnd)) as.integer(max(localDaily$DecYear,na.rm=TRUE)) else yearEnd

subDaily <- localDaily[localDaily$DecYear >= startYear & localDaily$DecYear <= endYear,]
subDaily <- localDaily[localDaily$DecYear >= yearStart & localDaily$DecYear <= yearEnd,]

xDaily <- subDaily$DecYear

Expand All @@ -101,7 +101,7 @@ plotQTimeDaily<-function (eList, startYear=NA, endYear=NA, qLower = NA, qUnit =
logText <- ""
}

xInfo <- generalAxis(x=xDaily, minVal=startYear, maxVal=endYear,
xInfo <- generalAxis(x=xDaily, minVal=yearStart, maxVal=yearEnd,
tinyPlot=tinyPlot, units=localINFO$param.units, prettyDate=prettyDate)
yInfo <- generalAxis(x=yDaily, minVal=qLower, maxVal=1.05*max(yDaily),
tinyPlot=tinyPlot,padPercent=0,logScale=logScale, units=localINFO$param.units)
Expand Down
Binary file modified inst/doc/EGRET.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion inst/doc/rResid.Rmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Using Random Residuals for Censored Data in EGRET"
author: "Robert M. Hirsch and Laura A. De Cicco"
date: "`r format(Sys.time(), '%d %B, %Y')`"
date: "2016-07-15"
output:
rmarkdown::html_vignette:
toc: true
Expand Down
15 changes: 8 additions & 7 deletions inst/doc/rResid.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion man/generalAxis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions man/plotConcTime.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c19c23d

Please sign in to comment.