Skip to content

Commit 95a23b7

Browse files
authored
Merge pull request #357 from stan-dev/qdotplot
add quantile dot plot functions
2 parents da5c707 + cd9f63f commit 95a23b7

16 files changed

+6600
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Imports:
4141
tidyselect,
4242
utils
4343
Suggests:
44+
ggdist,
4445
ggfortify,
4546
gridExtra (>= 2.2.1),
4647
hexbin,

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export(ppc_data)
123123
export(ppc_dens)
124124
export(ppc_dens_overlay)
125125
export(ppc_dens_overlay_grouped)
126+
export(ppc_dots)
126127
export(ppc_ecdf_overlay)
127128
export(ppc_ecdf_overlay_grouped)
128129
export(ppc_error_binned)
@@ -170,6 +171,7 @@ export(ppd_boxplot)
170171
export(ppd_data)
171172
export(ppd_dens)
172173
export(ppd_dens_overlay)
174+
export(ppd_dots)
173175
export(ppd_ecdf_overlay)
174176
export(ppd_freqpoly)
175177
export(ppd_freqpoly_grouped)

R/ppc-distributions.R

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#' @template args-pit-ecdf
1616
#' @param size,alpha Passed to the appropriate geom to control the appearance of
1717
#' the predictive distributions.
18-
#' @param ... Currently unused.
18+
#' @param ... For dot plots, optional additional arguments to pass to [ggdist::stat_dots()].
1919
#'
2020
#' @template details-binomial
2121
#' @template return-ggplot-or-data
@@ -28,14 +28,19 @@
2828
#' dataset (row) in `yrep`. For these plots `yrep` should therefore
2929
#' contain only a small number of rows. See the **Examples** section.
3030
#' }
31+
#' \item{`ppc_dots()`}{
32+
#' A dot plot plot is displayed for `y` and each dataset (row) in `yrep`.
33+
#' For these plots `yrep` should therefore contain only a small number of rows.
34+
#' See the **Examples** section. This function requires [ggdist::stat_dots] to be installed.
35+
#' }
3136
#' \item{`ppc_freqpoly_grouped()`}{
3237
#' A separate frequency polygon is plotted for each level of a grouping
3338
#' variable for `y` and each dataset (row) in `yrep`. For this plot
3439
#' `yrep` should therefore contain only a small number of rows. See the
3540
#' **Examples** section.
3641
#' }
37-
#' \item{`ppc_ecdf_overlay(), ppc_dens_overlay(),
38-
#' ppc_ecdf_overlay_grouped(), ppc_dens_overlay_grouped()`}{
42+
#' \item{`ppc_ecdf_overlay()`, `ppc_dens_overlay()`,
43+
#' `ppc_ecdf_overlay_grouped()`, `ppc_dens_overlay_grouped()`}{
3944
#' Kernel density or empirical CDF estimates of each dataset (row) in
4045
#' `yrep` are overlaid, with the distribution of `y` itself on top
4146
#' (and in a darker shade). When using `ppc_ecdf_overlay()` with discrete
@@ -80,7 +85,7 @@
8085
#' ppc_pit_ecdf(y, yrep, prob = 0.99, plot_diff = TRUE)
8186
#' }
8287
#'
83-
#' # for ppc_hist,dens,freqpoly,boxplot definitely use a subset yrep rows so
88+
#' # for ppc_hist,dens,freqpoly,boxplot,dots definitely use a subset yrep rows so
8489
#' # only a few (instead of nrow(yrep)) histograms are plotted
8590
#' ppc_hist(y, yrep[1:8, ])
8691
#' \donttest{
@@ -90,6 +95,9 @@
9095
#' # wizard hat plot
9196
#' color_scheme_set("blue")
9297
#' ppc_dens(y, yrep[200:202, ])
98+
#'
99+
#' # dot plot
100+
#' ppc_dots(y, yrep[1:8, ])
93101
#' }
94102
#'
95103
#' \donttest{
@@ -507,6 +515,45 @@ ppc_boxplot <-
507515
xaxis_title(FALSE)
508516
}
509517

518+
#' @rdname PPC-distributions
519+
#' @export
520+
#' @template args-dots
521+
ppc_dots <-
522+
function(y,
523+
yrep,
524+
...,
525+
binwidth = NA,
526+
quantiles = NA,
527+
freq = TRUE) {
528+
check_ignored_arguments(..., ok_args = c("dotsize", "layout", "stackratio", "overflow"))
529+
530+
suggested_package("ggdist")
531+
532+
data <- ppc_data(y, yrep)
533+
534+
ggplot(data, mapping = set_hist_aes(
535+
freq = freq,
536+
fill = .data$is_y_label,
537+
color = .data$is_y_label
538+
)) +
539+
ggdist::stat_dots(
540+
binwidth = binwidth,
541+
quantiles = quantiles,
542+
...
543+
) +
544+
scale_fill_ppc() +
545+
scale_color_ppc() +
546+
facet_wrap_parsed("rep_label") +
547+
force_axes_in_facets() +
548+
bayesplot_theme_get() +
549+
space_legend_keys() +
550+
yaxis_text(FALSE) +
551+
yaxis_title(FALSE) +
552+
yaxis_ticks(FALSE) +
553+
xaxis_title(FALSE) +
554+
facet_text(FALSE) +
555+
facet_bg(FALSE)
556+
}
510557

511558
#' @rdname PPC-distributions
512559
#' @export

R/ppd-distributions.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,43 @@ ppd_hist <-
187187
facet_text(FALSE)
188188
}
189189

190+
#' @rdname PPD-distributions
191+
#' @export
192+
ppd_dots <-
193+
function(ypred,
194+
...,
195+
binwidth = NA,
196+
quantiles = NA,
197+
freq = TRUE) {
198+
check_ignored_arguments(..., ok_args = c("dotsize", "layout", "stackratio", "overflow"))
199+
200+
suggested_package("ggdist")
201+
202+
data <- ppd_data(ypred)
203+
ggplot(data, mapping = set_hist_aes(
204+
freq,
205+
color = "ypred",
206+
fill = "ypred"
207+
)) +
208+
ggdist::stat_dots(
209+
binwidth = binwidth,
210+
quantiles = quantiles,
211+
...
212+
) +
213+
scale_color_ppd() +
214+
scale_fill_ppd() +
215+
bayesplot_theme_get() +
216+
facet_wrap_parsed("rep_label") +
217+
force_axes_in_facets() +
218+
dont_expand_y_axis() +
219+
legend_none() +
220+
yaxis_text(FALSE) +
221+
yaxis_title(FALSE) +
222+
yaxis_ticks(FALSE) +
223+
xaxis_title(FALSE) +
224+
facet_text(FALSE)
225+
}
226+
190227

191228
#' @rdname PPD-distributions
192229
#' @export

man-roxygen/args-dots.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#' @param quantiles For dot plots, an optional integer passed to
2+
#' [ggdist::stat_dots()] specifying the number of quantiles to use for a
3+
#' quantile dot plot. If `quantiles` is `NA` (the default) then all data
4+
#' points are plotted.

man/PPC-distributions.Rd

Lines changed: 20 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPD-distributions.Rd

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)