Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
86 changes: 80 additions & 6 deletions R/plotting_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
2 changes: 1 addition & 1 deletion R/rejection_sampling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ reference:
- interpolate_stage_matrix
- power_function
- theme_rfar_conceptual
- scale_x_aep
- pmf_stage_lognormal
- rejection_sampling_stage
- title: "Datasets"
Expand Down
2 changes: 1 addition & 1 deletion man/rejection_sampling_stage.Rd

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

54 changes: 54 additions & 0 deletions man/scale_x_aep.Rd

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

Loading