diff --git a/NEWS.md b/NEWS.md
index 7525658eb..fceb6a8f8 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,5 +1,6 @@
# bayesplot (development version)
+* `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated.
* Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`.
* Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.
* Fixed `is_chain_list()` to correctly reject empty lists instead of silently returning `TRUE`.
diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R
index d32a2e1a7..7ab9ffb81 100644
--- a/R/ppc-distributions.R
+++ b/R/ppc-distributions.R
@@ -41,11 +41,10 @@
#' }
#' \item{`ppc_ecdf_overlay()`, `ppc_dens_overlay()`,
#' `ppc_ecdf_overlay_grouped()`, `ppc_dens_overlay_grouped()`}{
-#' Kernel density or empirical CDF estimates of each dataset (row) in
-#' `yrep` are overlaid, with the distribution of `y` itself on top
-#' (and in a darker shade). When using `ppc_ecdf_overlay()` with discrete
-#' data, set the `discrete` argument to `TRUE` for better results.
-#' For an example of `ppc_dens_overlay()` also see Gabry et al. (2019).
+#' Kernel density or empirical CDF estimates of each dataset (row) in `yrep`
+#' are overlaid, with the distribution of `y` itself on top (and in a darker
+#' shade). For an example of `ppc_dens_overlay()` also see Gabry et al.
+#' (2019).
#' }
#' \item{`ppc_violin_grouped()`}{
#' The density estimate of `yrep` within each level of a grouping
@@ -85,7 +84,7 @@
#'
#' ppc_dens_overlay(y, yrep[1:25, ])
#' \donttest{
-#' # ppc_ecdf_overlay with continuous data (set discrete=TRUE if discrete data)
+#' # ppc_ecdf_overlay
#' ppc_ecdf_overlay(y, yrep[sample(nrow(yrep), 25), ])
#'
#' # PIT-ECDF and PIT-ECDF difference plot of the PIT values of y compared to
@@ -258,20 +257,28 @@ ppc_dens_overlay_grouped <- function(y,
#' @export
#' @rdname PPC-distributions
-#' @param discrete For `ppc_ecdf_overlay()`, should the data be treated as
-#' discrete? The default is `FALSE`, in which case `geom="line"` is
-#' passed to [ggplot2::stat_ecdf()]. If `discrete` is set to
-#' `TRUE` then `geom="step"` is used.
+#' @param discrete `r lifecycle::badge("deprecated")` The `discrete` argument is
+#' deprecated. The ECDF is a step function by definition, so `geom_step()` is
+#' now always used.
#' @param pad A logical scalar passed to [ggplot2::stat_ecdf()].
#'
ppc_ecdf_overlay <- function(y,
yrep,
...,
- discrete = FALSE,
+ discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7) {
check_ignored_arguments(...)
+
+ if (is_present(discrete)) {
+ deprecate_warn(
+ "1.16.0",
+ "ppc_ecdf_overlay(discrete)",
+ details = "The ECDF is now always plotted as a step function."
+ )
+ }
+
data <- ppc_data(y, yrep)
ggplot(data) +
@@ -291,7 +298,7 @@ ppc_ecdf_overlay <- function(y,
stat_ecdf(
data = function(x) dplyr::filter(x, !.data$is_y),
mapping = aes(group = .data$rep_id, color = "yrep"),
- geom = if (discrete) "step" else "line",
+ geom = "step",
linewidth = size,
alpha = alpha,
pad = pad
@@ -299,7 +306,7 @@ ppc_ecdf_overlay <- function(y,
stat_ecdf(
data = function(x) dplyr::filter(x, .data$is_y),
mapping = aes(color = "y"),
- geom = if (discrete) "step" else "line",
+ geom = "step",
linewidth = 1,
pad = pad
) +
@@ -316,17 +323,24 @@ ppc_ecdf_overlay_grouped <- function(y,
yrep,
group,
...,
- discrete = FALSE,
+ discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7) {
check_ignored_arguments(...)
+ if (is_present(discrete)) {
+ deprecate_warn(
+ "1.16.0",
+ "ppc_ecdf_overlay_grouped(discrete)",
+ details = "The ECDF is now always plotted as a step function."
+ )
+ }
+
p_overlay <- ppc_ecdf_overlay(
y = y,
yrep = yrep,
...,
- discrete = discrete,
pad = pad,
size = size,
alpha = alpha
diff --git a/R/ppd-distributions.R b/R/ppd-distributions.R
index 70c4e5a68..fca2d5ee2 100644
--- a/R/ppd-distributions.R
+++ b/R/ppd-distributions.R
@@ -83,12 +83,20 @@ ppd_dens_overlay <-
ppd_ecdf_overlay <-
function(ypred,
...,
- discrete = FALSE,
+ discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7) {
check_ignored_arguments(...)
+ if (is_present(discrete)) {
+ deprecate_warn(
+ "1.16.0",
+ "ppd_ecdf_overlay(discrete)",
+ details = "The ECDF is now always plotted as a step function."
+ )
+ }
+
data <- ppd_data(ypred)
ggplot(data, mapping = aes(x = .data$value)) +
hline_at(
@@ -99,7 +107,7 @@ ppd_ecdf_overlay <-
) +
stat_ecdf(
mapping = aes(group = .data$rep_id, color = "ypred"),
- geom = if (discrete) "step" else "line",
+ geom = "step",
linewidth = size,
alpha = alpha,
pad = pad
diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd
index b0099f2d1..b02cc26cf 100644
--- a/man/PPC-distributions.Rd
+++ b/man/PPC-distributions.Rd
@@ -53,7 +53,7 @@ ppc_ecdf_overlay(
y,
yrep,
...,
- discrete = FALSE,
+ discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7
@@ -64,7 +64,7 @@ ppc_ecdf_overlay_grouped(
yrep,
group,
...,
- discrete = FALSE,
+ discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7
@@ -174,10 +174,9 @@ the predictive distributions.}
default kernel density estimation parameters or truncate the density
support. \code{n_dens} defaults to \code{1024}.}
-\item{discrete}{For \code{ppc_ecdf_overlay()}, should the data be treated as
-discrete? The default is \code{FALSE}, in which case \code{geom="line"} is
-passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}. If \code{discrete} is set to
-\code{TRUE} then \code{geom="step"} is used.}
+\item{discrete}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} The \code{discrete} argument is
+deprecated. The ECDF is a step function by definition, so \code{geom_step()} is
+now always used.}
\item{pad}{A logical scalar passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}.}
@@ -283,11 +282,10 @@ variable for \code{y} and each dataset (row) in \code{yrep}. For this plot
}
\item{\code{ppc_ecdf_overlay()}, \code{ppc_dens_overlay()},
\code{ppc_ecdf_overlay_grouped()}, \code{ppc_dens_overlay_grouped()}}{
-Kernel density or empirical CDF estimates of each dataset (row) in
-\code{yrep} are overlaid, with the distribution of \code{y} itself on top
-(and in a darker shade). When using \code{ppc_ecdf_overlay()} with discrete
-data, set the \code{discrete} argument to \code{TRUE} for better results.
-For an example of \code{ppc_dens_overlay()} also see Gabry et al. (2019).
+Kernel density or empirical CDF estimates of each dataset (row) in \code{yrep}
+are overlaid, with the distribution of \code{y} itself on top (and in a darker
+shade). For an example of \code{ppc_dens_overlay()} also see Gabry et al.
+(2019).
}
\item{\code{ppc_violin_grouped()}}{
The density estimate of \code{yrep} within each level of a grouping
@@ -323,7 +321,7 @@ dim(yrep)
ppc_dens_overlay(y, yrep[1:25, ])
\donttest{
-# ppc_ecdf_overlay with continuous data (set discrete=TRUE if discrete data)
+# ppc_ecdf_overlay
ppc_ecdf_overlay(y, yrep[sample(nrow(yrep), 25), ])
# PIT-ECDF and PIT-ECDF difference plot of the PIT values of y compared to
diff --git a/man/PPD-distributions.Rd b/man/PPD-distributions.Rd
index a53c62e40..7517ec254 100644
--- a/man/PPD-distributions.Rd
+++ b/man/PPD-distributions.Rd
@@ -31,7 +31,7 @@ ppd_dens_overlay(
ppd_ecdf_overlay(
ypred,
...,
- discrete = FALSE,
+ discrete = deprecated(),
pad = TRUE,
size = 0.25,
alpha = 0.7
@@ -89,10 +89,9 @@ the predictive distributions.}
default kernel density estimation parameters or truncate the density
support. \code{n_dens} defaults to \code{1024}.}
-\item{discrete}{For \code{ppc_ecdf_overlay()}, should the data be treated as
-discrete? The default is \code{FALSE}, in which case \code{geom="line"} is
-passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}. If \code{discrete} is set to
-\code{TRUE} then \code{geom="step"} is used.}
+\item{discrete}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} The \code{discrete} argument is
+deprecated. The ECDF is a step function by definition, so \code{geom_step()} is
+now always used.}
\item{pad}{A logical scalar passed to \code{\link[ggplot2:stat_ecdf]{ggplot2::stat_ecdf()}}.}
diff --git a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-default.svg b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-default.svg
index 56e21f82c..4b7eac4c2 100644
--- a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-default.svg
+++ b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-default.svg
@@ -28,17 +28,17 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-default.svg b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-default.svg
index 029410fbd..fdd8a4393 100644
--- a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-default.svg
+++ b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-default.svg
@@ -28,17 +28,17 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -53,17 +53,17 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-discrete-size-alpha.svg b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-size-alpha.svg
similarity index 99%
rename from tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-discrete-size-alpha.svg
rename to tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-size-alpha.svg
index cb9301ac4..f42c93307 100644
--- a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-discrete-size-alpha.svg
+++ b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-grouped-size-alpha.svg
@@ -128,6 +128,6 @@
rep
-ppc_ecdf_overlay_grouped (discrete, size, alpha)
+ppc_ecdf_overlay_grouped (size, alpha)
diff --git a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-discrete-size-alpha.svg b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-size-alpha.svg
similarity index 98%
rename from tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-discrete-size-alpha.svg
rename to tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-size-alpha.svg
index e35e25a85..e10910898 100644
--- a/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-discrete-size-alpha.svg
+++ b/tests/testthat/_snaps/ppc-distributions/ppc-ecdf-overlay-size-alpha.svg
@@ -68,6 +68,6 @@
rep
-ppc_ecdf_overlay (discrete, size, alpha)
+ppc_ecdf_overlay (size, alpha)
diff --git a/tests/testthat/_snaps/ppc-distributions/ppd-ecdf-overlay-default.svg b/tests/testthat/_snaps/ppc-distributions/ppd-ecdf-overlay-default.svg
new file mode 100644
index 000000000..4dff5a697
--- /dev/null
+++ b/tests/testthat/_snaps/ppc-distributions/ppd-ecdf-overlay-default.svg
@@ -0,0 +1,63 @@
+
+
diff --git a/tests/testthat/test-ppc-distributions.R b/tests/testthat/test-ppc-distributions.R
index 34e1c82f4..0bab48206 100644
--- a/tests/testthat/test-ppc-distributions.R
+++ b/tests/testthat/test-ppc-distributions.R
@@ -50,6 +50,22 @@ test_that("ppc_ecdf_overlay returns a ggplot object", {
expect_gg(ppd_ecdf_overlay(yrep2))
})
+test_that("ppc_ecdf_overlay discrete argument is deprecated", {
+ lifecycle::expect_deprecated(
+ ppc_ecdf_overlay(vdiff_y2, vdiff_yrep2, discrete = TRUE)
+ )
+ lifecycle::expect_deprecated(
+ ppc_ecdf_overlay_grouped(vdiff_y2, vdiff_yrep2, vdiff_group2, discrete = TRUE)
+ )
+ lifecycle::expect_deprecated(
+ ppd_ecdf_overlay(vdiff_yrep2, discrete = TRUE)
+ )
+
+ # no warning when discrete is not supplied
+ expect_no_warning(ppc_ecdf_overlay(vdiff_y2, vdiff_yrep2))
+ expect_no_warning(ppd_ecdf_overlay(vdiff_yrep2))
+})
+
test_that("ppc_dens,pp_hist,ppc_freqpoly,ppc_boxplot return ggplot objects", {
expect_gg(ppc_hist(y, yrep[1,, drop = FALSE], binwidth = 0.1))
expect_gg(ppc_hist(y, yrep[1:8, ], binwidth = 0.1))
@@ -360,13 +376,12 @@ test_that("ppc_ecdf_overlay renders correctly", {
p_custom <- ppc_ecdf_overlay(
vdiff_y2,
vdiff_yrep2,
- discrete = TRUE,
size = 2,
alpha = .2
)
vdiffr::expect_doppelganger(
- "ppc_ecdf_overlay (discrete, size, alpha)",
+ "ppc_ecdf_overlay (size, alpha)",
p_custom
)
})
@@ -383,17 +398,25 @@ test_that("ppc_ecdf_overlay_grouped renders correctly", {
vdiff_y2,
vdiff_yrep2,
vdiff_group2,
- discrete = TRUE,
size = 2,
alpha = .2
)
vdiffr::expect_doppelganger(
- "ppc_ecdf_overlay_grouped (discrete, size, alpha)",
+ "ppc_ecdf_overlay_grouped (size, alpha)",
p_custom
)
})
+test_that("ppd_ecdf_overlay renders correctly", {
+ testthat::skip_on_cran()
+ testthat::skip_if_not_installed("vdiffr")
+ skip_on_r_oldrel()
+
+ p_base <- ppd_ecdf_overlay(vdiff_yrep2)
+ vdiffr::expect_doppelganger("ppd_ecdf_overlay (default)", p_base)
+})
+
test_that("ppc_dens renders correctly", {
testthat::skip_on_cran()
testthat::skip_if_not_installed("vdiffr")