|
17 | 17 | #' the predictive distributions. |
18 | 18 | #' @param ... For dot plots, optional additional arguments to pass to [ggdist::stat_dots()]. |
19 | 19 | #' |
| 20 | +#' @param binwidth Numeric scalar; passed to the underlying geom/stat used |
| 21 | +#' by the plotting function. Behavior by function: |
| 22 | +#' * `ppc_hist()`: forwarded to `ggplot2::geom_histogram(binwidth = ...)`. |
| 23 | +#' * `ppc_freqpoly()` / `ppc_freqpoly_grouped()`: forwarded to |
| 24 | +#' `ggplot2::geom_area(stat = "bin", binwidth = ...)` (i.e. `stat = "bin"`). |
| 25 | +#' * `ppc_dots()`: forwarded to `ggdist::stat_dots(binwidth = ...)`. |
| 26 | +#' If `NULL`, the default binning behavior of the respective geom/stat is used. |
| 27 | +#' |
| 28 | +#' @param bins Integer number of bins. Forwarded in the same way as `binwidth` |
| 29 | +#' (i.e. to `geom_histogram()`, `geom_area(stat = "bin")`, and `ggdist::stat_dots()`). |
| 30 | +#' |
| 31 | +#' @param breaks Numeric vector of break positions. Forwarded in the same way |
| 32 | +#' as `binwidth`/`bins` (where supported). |
| 33 | +#' |
| 34 | +#' @param freq Logical. Controls whether the vertical scale shows counts |
| 35 | +#' (`freq = TRUE`) or densities/proportions (`freq = FALSE`). This argument |
| 36 | +#' is not limited to `ppc_hist()` — it is also used by `ppc_freqpoly()` and |
| 37 | +#' `ppc_freqpoly_grouped()` because those functions use `stat="bin"` |
| 38 | +#' (implemented via `geom_area(stat = "bin")`). The `freq` value is passed |
| 39 | +#' to `set_hist_aes()` and affects the y aesthetic used by `geom_histogram()` |
| 40 | +#' and `geom_area(stat="bin")`. |
| 41 | +#' |
20 | 42 | #' @template details-binomial |
21 | 43 | #' @template return-ggplot-or-data |
22 | 44 | #' |
| 45 | +#' @section Version & Dependencies: |
| 46 | +#' |
| 47 | +#' - Requires **ggplot2 (>= 3.4.0)** for the use of modern layering and |
| 48 | +#' consistent handling of bin arguments. |
| 49 | +#' |
| 50 | +#' - Uses **ggdist::stat_dots()** (requires **ggdist >= 3.3.0**). |
| 51 | +#' |
| 52 | +#' - All `ppc_*` functions depend on **bayesplot** core plotting infrastructure |
| 53 | +#' and `ggplot2` grammar of graphics. |
| 54 | +#' |
| 55 | +#' - Ensure that dependent packages (`ggplot2`, `ggdist`, and `bayesplot`) |
| 56 | +#' are loaded or properly imported in your package’s `DESCRIPTION` file. |
| 57 | +#' |
23 | 58 | #' @section Plot Descriptions: |
24 | 59 | #' \describe{ |
25 | 60 | #' \item{`ppc_hist(), ppc_freqpoly(), ppc_dens(), ppc_boxplot()`}{ |
|
62 | 97 | #' See Säilynoja et al. (2021) for more details.} |
63 | 98 | #' } |
64 | 99 | #' |
| 100 | +#' @section When to Use Each Plot: |
| 101 | +#' |
| 102 | +#' These plots offer different perspectives on how simulated (`yrep`) and observed (`y`) data compare. |
| 103 | +#' |
| 104 | +#' \itemize{ |
| 105 | +#' \item **`ppc_hist()`** — Best for visualizing **overall distribution shapes**. |
| 106 | +#' Use this when your data are continuous and you want to see how model predictions align |
| 107 | +#' with observed distributions. |
| 108 | +#' |
| 109 | +#' \item **`ppc_dots()`** — Ideal for **small or discrete datasets**. |
| 110 | +#' Displays each simulated dataset as dots, giving an intuitive visual comparison |
| 111 | +#' between simulated and observed values. |
| 112 | +#' |
| 113 | +#' \item **`ppc_freqpoly()`** — Useful for **moderate to large continuous datasets**. |
| 114 | +#' Highlights how predicted and observed **frequencies vary** across the range of `y`. |
| 115 | +#' |
| 116 | +#' \item **`ppc_freqpoly_grouped()`** — When you have a **grouping variable** (e.g., categories), |
| 117 | +#' use this to compare frequencies across levels of that variable. |
| 118 | +#' } |
| 119 | +#' |
| 120 | +#' @section Usage Note: |
| 121 | +#' |
| 122 | +#' - The `binwidth`, `bins`, and `breaks` arguments are passed to multiple |
| 123 | +#' underlying `ggplot2` and `ggdist` geoms (`geom_histogram()`, `geom_area()`, |
| 124 | +#' and `stat_dots()`), which means they affect both histogram and dot plot outputs. |
| 125 | +#' |
| 126 | +#' - The `freq` argument controls whether the y-axis represents **counts** |
| 127 | +#' (`freq = TRUE`) or **densities** (`freq = FALSE`) for both histograms |
| 128 | +#' and frequency polygons. |
| 129 | +#' |
| 130 | +#' - These plots assume numeric `y` values. For categorical data, |
| 131 | +#' consider `ppc_bars()` or similar discrete comparison functions. |
| 132 | +#' |
| 133 | +#' - If a grouping variable is provided, ensure that `y` and `yrep` have |
| 134 | +#' matching group structures; otherwise, plots may not align correctly. |
| 135 | +#' |
| 136 | +#' - For large replicated datasets (`yrep` with > 50 rows), consider |
| 137 | +#' summarizing or subsampling to avoid overplotting. |
| 138 | +#' |
| 139 | +#' Note: |
| 140 | +#' The `binwidth`, `bins`, and `breaks` arguments are forwarded not only |
| 141 | +#' to `ggplot2::geom_histogram()` (used by `ppc_hist()`), but also to |
| 142 | +#' `ggdist::stat_dots()` (used by `ppc_dots()`) and to the `stat = "bin"` |
| 143 | +#' layers used by `ppc_freqpoly()` and `ppc_freqpoly_grouped()` |
| 144 | +#' (implemented with `ggplot2::geom_area(stat = "bin", ...)`). |
| 145 | +#' |
| 146 | +#' Similarly, the `freq` argument affects not only histograms but also |
| 147 | +#' frequency polygons created with `ppc_freqpoly()` and |
| 148 | +#' `ppc_freqpoly_grouped()`, where it determines whether the y-axis |
| 149 | +#' represents counts (`freq = TRUE`) or densities (`freq = FALSE`). |
| 150 | +#' |
65 | 151 | #' @template reference-vis-paper |
66 | 152 | #' @template reference-uniformity-test |
67 | 153 | #' @templateVar bdaRef (Ch. 6) |
|
0 commit comments