From 6c86591a153d293458ad9a6cadb43a2f71dbb3ce Mon Sep 17 00:00:00 2001 From: Dan McGraw Date: Wed, 4 Nov 2026 12:25:14 -0700 Subject: [PATCH 1/3] Update plot theme and rejection sampling documentation --- R/plotting_utils.R | 86 +++++++++++++++++++++++++++++++++++++++--- R/rejection_sampling.R | 2 +- 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/R/plotting_utils.R b/R/plotting_utils.R index bcf610ad..f42a398c 100644 --- a/R/plotting_utils.R +++ b/R/plotting_utils.R @@ -21,11 +21,85 @@ #' subtitle = "Demonstrating theme_rfar_conceptual()", #' x = "AEP", y = "Stage (ft)") + #' theme_rfar_conceptual() -theme_rfar_conceptual <- function(){ +theme_rfar_conceptual <- function() { ggplot2::theme_bw() + - ggplot2::theme(legend.position = "none", - plot.title = ggplot2::element_text(size = 11, face = "bold.italic"), - plot.subtitle = ggplot2::element_text(size = 8, face = "italic"), - axis.title = ggplot2::element_text(size = 9, face = "bold"), - axis.text = ggplot2::element_text(size = 8)) + ggplot2::theme( + legend.position = "none", + plot.title = ggplot2::element_text(size = 11, face = "bold.italic"), + plot.subtitle = ggplot2::element_text(size = 8, face = "italic"), + axis.title = ggplot2::element_text(size = 9, face = "bold"), + axis.text = ggplot2::element_text(size = 8) + ) +} + +#' AEP-Labelled Normal-Variate X Scale +#' +#' Creates a continuous \pkg{ggplot2} x-axis positioned on the standard-normal +#' variate scale while displaying labels as annual exceedance probabilities +#' (AEPs). This is useful for stage-frequency, flow-frequency, and similar +#' conceptual plots where values are modeled or transformed in normal-variate +#' space but should be interpreted as probabilities. +#' +#' Major breaks are specified as AEP values and transformed using +#' \code{qnorm(1 - AEP)}. Minor breaks are generated from the supplied +#' multipliers across AEP decades from \eqn{10^{-1}} through \eqn{10^{-10}}. +#' +#' @param aep_breaks Numeric vector of annual exceedance probabilities to use +#' as major axis breaks. Values must be greater than 0 and less than 1. +#' Defaults range from 0.99 through \eqn{10^{-10}}. +#' @param minor_aep Numeric vector of multipliers used to generate minor AEP +#' breaks within each decade. The default, \code{2:9}, produces minor breaks +#' such as 0.2 through 0.9, 0.02 through 0.09, and so on. +#' +#' @return A \pkg{ggplot2} continuous x-scale object that can be added to a +#' \code{ggplot} via \code{+}. +#' +#' @export +#' +#' @examples +#' library(ggplot2) +#' +#' example_data <- data.frame( +#' AEP = c(0.99, 0.5, 0.1, 0.01, 0.001), +#' Stage = c(10.2, 11.5, 14.0, 17.3, 20.1) +#' ) +#' +#' ggplot(example_data, aes(x = qnorm(1 - AEP), y = Stage)) + +#' geom_line() + +#' scale_x_aep() + +#' labs( +#' title = "Example Stage-Frequency Curve", +#' x = "Annual Exceedance Probability", +#' y = "Stage (ft)" +#' ) +scale_x_aep <- function( + aep_breaks = c( + 9.9e-1, + 9e-1, + 5e-1, + 1e-1, + 1e-2, + 1e-3, + 1e-4, + 1e-5, + 1e-6, + 1e-7, + 1e-8, + 1e-9, + 1e-10 + ), + minor_aep = 2:9 +) { + minor_aep_breaks <- unlist( + lapply(minor_aep, function(i) i * 10^-(1:10)) + ) + + z_breaks <- stats::qnorm(1 - aep_breaks) + z_breaks_minor <- stats::qnorm(1 - minor_aep_breaks) + + ggplot2::scale_x_continuous( + breaks = z_breaks, + minor_breaks = z_breaks_minor, + labels = aep_breaks + ) } diff --git a/R/rejection_sampling.R b/R/rejection_sampling.R index c53103e7..0a6138b0 100644 --- a/R/rejection_sampling.R +++ b/R/rejection_sampling.R @@ -160,7 +160,7 @@ pmf_stage_lognormal <- function( #' #' @examples #' -#' pmf_ln <- pmf_stage_lognormal(pmf_shift = 239, pmf_mean = 241.9, pmf_sigma = 0.5) +#' pmf_ln <- pmf_stage_lognormal(pmf_shift = 1651, pmf_mean = 1663, pmf_sigma = 0.5) #' result <- rejection_sampling_stage( #' pmf_stage_LN = pmf_ln, #' stage_freq_df = ex_rs_stage_loading, From af46117f7e05da755ac73e73b1a3a45995956b5b Mon Sep 17 00:00:00 2001 From: Dan McGraw Date: Wed, 4 Nov 2026 13:18:11 -0700 Subject: [PATCH 2/3] devtools:doc --- NAMESPACE | 1 + man/rejection_sampling_stage.Rd | 2 +- man/scale_x_aep.Rd | 54 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 man/scale_x_aep.Rd diff --git a/NAMESPACE b/NAMESPACE index 2267f619..011f5f33 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(qp3) export(rejection_sampling_stage) export(rfa_simulate) export(scale_hydrograph) +export(scale_x_aep) export(stage2aep) export(stratified_sampler) export(theme_rfar_conceptual) diff --git a/man/rejection_sampling_stage.Rd b/man/rejection_sampling_stage.Rd index 86599601..3768841e 100644 --- a/man/rejection_sampling_stage.Rd +++ b/man/rejection_sampling_stage.Rd @@ -40,7 +40,7 @@ assigned Weibull plotting positions for use in frequency analysis. } \examples{ -pmf_ln <- pmf_stage_lognormal(pmf_shift = 239, pmf_mean = 241.9, pmf_sigma = 0.5) +pmf_ln <- pmf_stage_lognormal(pmf_shift = 1651, pmf_mean = 1663, pmf_sigma = 0.5) result <- rejection_sampling_stage( pmf_stage_LN = pmf_ln, stage_freq_df = ex_rs_stage_loading, diff --git a/man/scale_x_aep.Rd b/man/scale_x_aep.Rd new file mode 100644 index 00000000..c14fa976 --- /dev/null +++ b/man/scale_x_aep.Rd @@ -0,0 +1,54 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plotting_utils.R +\name{scale_x_aep} +\alias{scale_x_aep} +\title{AEP-Labelled Normal-Variate X Scale} +\usage{ +scale_x_aep( + aep_breaks = c(0.99, 0.9, 0.5, 0.1, 0.01, 0.001, 1e-04, 1e-05, 1e-06, 1e-07, 1e-08, + 1e-09, 1e-10), + minor_aep = 2:9 +) +} +\arguments{ +\item{aep_breaks}{Numeric vector of annual exceedance probabilities to use +as major axis breaks. Values must be greater than 0 and less than 1. +Defaults range from 0.99 through \eqn{10^{-10}}.} + +\item{minor_aep}{Numeric vector of multipliers used to generate minor AEP +breaks within each decade. The default, \code{2:9}, produces minor breaks +such as 0.2 through 0.9, 0.02 through 0.09, and so on.} +} +\value{ +A \pkg{ggplot2} continuous x-scale object that can be added to a +\code{ggplot} via \code{+}. +} +\description{ +Creates a continuous \pkg{ggplot2} x-axis positioned on the standard-normal +variate scale while displaying labels as annual exceedance probabilities +(AEPs). This is useful for stage-frequency, flow-frequency, and similar +conceptual plots where values are modeled or transformed in normal-variate +space but should be interpreted as probabilities. +} +\details{ +Major breaks are specified as AEP values and transformed using +\code{qnorm(1 - AEP)}. Minor breaks are generated from the supplied +multipliers across AEP decades from \eqn{10^{-1}} through \eqn{10^{-10}}. +} +\examples{ +library(ggplot2) + +example_data <- data.frame( + AEP = c(0.99, 0.5, 0.1, 0.01, 0.001), + Stage = c(10.2, 11.5, 14.0, 17.3, 20.1) +) + +ggplot(example_data, aes(x = qnorm(1 - AEP), y = Stage)) + + geom_line() + + scale_x_aep() + + labs( + title = "Example Stage-Frequency Curve", + x = "Annual Exceedance Probability", + y = "Stage (ft)" + ) +} From 632ab0ce31c0b5bdfba0cc86906b6b6c1a1fd37b Mon Sep 17 00:00:00 2001 From: Dan McGraw Date: Wed, 4 Nov 2026 14:33:26 -0700 Subject: [PATCH 3/3] updated yaml --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 9f46270a..20dd302c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -46,6 +46,7 @@ reference: - interpolate_stage_matrix - power_function - theme_rfar_conceptual + - scale_x_aep - pmf_stage_lognormal - rejection_sampling_stage - title: "Datasets"