Skip to content

Commit 3786d63

Browse files
committed
Add bins and breaks for histogram and hex plots
This is a follow-up of #285 and #300.
1 parent 307d744 commit 3786d63

14 files changed

+96
-17
lines changed

R/mcmc-diagnostics-nuts.R

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,16 @@ NULL
127127

128128
#' @rdname MCMC-nuts
129129
#' @export
130-
#' @param binwidth An optional value passed to [ggplot2::geom_histogram()] to
131-
#' override the default binwidth.
130+
#' @template args-hist
132131
#'
133132
mcmc_nuts_acceptance <-
134133
function(x,
135134
lp,
136135
chain = NULL,
137136
...,
138-
binwidth = NULL) {
137+
binwidth = NULL,
138+
bins = NULL,
139+
breaks = NULL) {
139140
suggested_package("gridExtra")
140141
check_ignored_arguments(...)
141142

@@ -160,7 +161,9 @@ mcmc_nuts_acceptance <-
160161
color = get_color("lh"),
161162
linewidth = 0.25,
162163
na.rm = TRUE,
163-
binwidth = binwidth
164+
binwidth = binwidth,
165+
bins = bins,
166+
breaks = breaks
164167
) +
165168
bayesplot_theme_get()
166169

@@ -209,7 +212,9 @@ mcmc_nuts_acceptance <-
209212
color = NA,
210213
alpha = 0.5,
211214
na.rm = TRUE,
212-
binwidth = binwidth
215+
binwidth = binwidth,
216+
bins = bins,
217+
breaks = breaks
213218
)
214219

215220
chain_scatter_data <- data.frame(
@@ -417,6 +422,8 @@ mcmc_nuts_energy <-
417422
function(x,
418423
...,
419424
binwidth = NULL,
425+
bins = NULL,
426+
breaks = NULL,
420427
alpha = 0.5,
421428
merge_chains = FALSE) {
422429
check_ignored_arguments(...)
@@ -446,7 +453,9 @@ mcmc_nuts_energy <-
446453
),
447454
linewidth = 0.25,
448455
na.rm = TRUE,
449-
binwidth = binwidth
456+
binwidth = binwidth,
457+
bins = bins,
458+
breaks = breaks
450459
) +
451460
geom_histogram(
452461
aes(
@@ -457,7 +466,9 @@ mcmc_nuts_energy <-
457466
linewidth = 0.25,
458467
na.rm = TRUE,
459468
alpha = alpha,
460-
binwidth = binwidth
469+
binwidth = binwidth,
470+
bins = bins,
471+
breaks = breaks
461472
) +
462473
scale_fill_manual("", values = fills, labels = aes_labs) +
463474
scale_color_manual("", values = clrs, labels = aes_labs) +

R/mcmc-scatterplots.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' @param ... Currently ignored.
1414
#' @param size,alpha For `mcmc_scatter()`, passed to
1515
#' [ggplot2::geom_point()] to control the appearance of the points.
16-
#' @param binwidth For `mcmc_hex()`, an optional numeric vector of
16+
#' @param bins,binwidth For `mcmc_hex()`, an optional numeric vector of
1717
#' *length two* passed to [ggplot2::geom_hex()] to override the
1818
#' default binwidth in both the vertical and horizontal directions.
1919
#'
@@ -156,6 +156,7 @@ mcmc_hex <- function(x,
156156
regex_pars = character(),
157157
transformations = list(),
158158
...,
159+
bins = 30,
159160
binwidth = NULL) {
160161
suggested_package("scales")
161162
suggested_package("hexbin")
@@ -166,6 +167,7 @@ mcmc_hex <- function(x,
166167
regex_pars = regex_pars,
167168
transformations = transformations,
168169
hex = TRUE,
170+
bins = bins,
169171
binwidth = binwidth,
170172
size = NULL,
171173
alpha = NULL
@@ -641,6 +643,7 @@ pairs_condition <- function(chains = NULL, draws = NULL, nuts = NULL) {
641643
hex = FALSE,
642644
size = 2.5,
643645
alpha = 0.8,
646+
bins = 30,
644647
binwidth = NULL,
645648
np = NULL,
646649
np_style = scatter_style_np()) {
@@ -702,6 +705,7 @@ pairs_condition <- function(chains = NULL, draws = NULL, nuts = NULL) {
702705
graph <- graph +
703706
geom_hex(
704707
aes(fill = scales::rescale(after_stat(density))),
708+
bins = bins,
705709
binwidth = binwidth
706710
) +
707711
scale_fill_gradientn(

R/ppc-distributions.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ ppc_freqpoly <-
402402
yrep,
403403
...,
404404
binwidth = NULL,
405+
bins = NULL,
405406
freq = TRUE,
406407
size = 0.5,
407408
alpha = 1) {
@@ -420,6 +421,7 @@ ppc_freqpoly <-
420421
geom_area(
421422
stat = "bin",
422423
binwidth = binwidth,
424+
bins = bins,
423425
linewidth = size,
424426
alpha = alpha
425427
) +
@@ -446,6 +448,7 @@ ppc_freqpoly_grouped <-
446448
group,
447449
...,
448450
binwidth = NULL,
451+
bins = NULL,
449452
freq = TRUE,
450453
size = 0.5,
451454
alpha = 1) {

R/ppc-errors.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ ppc_error_hist_grouped <-
164164
...,
165165
facet_args = list(),
166166
binwidth = NULL,
167+
bins = NULL,
167168
breaks = NULL,
168169
freq = TRUE) {
169170

R/ppc-test-statistics.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ ppc_stat_grouped <-
165165
...,
166166
facet_args = list(),
167167
binwidth = NULL,
168+
bins = NULL,
168169
breaks = NULL,
169170
freq = TRUE) {
170171
check_ignored_arguments(...)
@@ -185,6 +186,7 @@ ppc_stat_freqpoly <-
185186
...,
186187
facet_args = list(),
187188
binwidth = NULL,
189+
bins = NULL,
188190
freq = TRUE) {
189191
stopifnot(length(stat) == 1)
190192
dots <- list(...)
@@ -208,7 +210,8 @@ ppc_stat_freqpoly <-
208210
aes(color = "yrep"),
209211
linewidth = 0.5,
210212
na.rm = TRUE,
211-
binwidth = binwidth
213+
binwidth = binwidth,
214+
bins = bins
212215
) +
213216
geom_vline(
214217
data = dplyr::filter(data, .data$variable == "y"),
@@ -240,6 +243,7 @@ ppc_stat_freqpoly_grouped <-
240243
...,
241244
facet_args = list(),
242245
binwidth = NULL,
246+
bins = NULL,
243247
freq = TRUE) {
244248
check_ignored_arguments(...)
245249
call <- match.call(expand.dots = FALSE)

R/ppd-distributions.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ ppd_freqpoly <-
194194
function(ypred,
195195
...,
196196
binwidth = NULL,
197+
bins = NULL,
197198
freq = TRUE,
198199
size = 0.5,
199200
alpha = 1) {
@@ -213,6 +214,7 @@ ppd_freqpoly <-
213214
geom_area(
214215
stat = "bin",
215216
binwidth = binwidth,
217+
bins = bins,
216218
size = size,
217219
alpha = alpha
218220
) +
@@ -238,6 +240,7 @@ ppd_freqpoly_grouped <-
238240
group,
239241
...,
240242
binwidth = NULL,
243+
bins = NULL,
241244
freq = TRUE,
242245
size = 0.5,
243246
alpha = 1) {

R/ppd-test-statistics.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ ppd_stat_grouped <-
8585
...,
8686
facet_args = list(),
8787
binwidth = NULL,
88+
bins = NULL,
8889
breaks = NULL,
8990
freq = TRUE) {
9091
check_ignored_arguments(...)
@@ -104,6 +105,7 @@ ppd_stat_freqpoly <-
104105
...,
105106
facet_args = list(),
106107
binwidth = NULL,
108+
bins = NULL,
107109
freq = TRUE) {
108110
stopifnot(length(stat) == 1)
109111
dots <- list(...)
@@ -122,7 +124,8 @@ ppd_stat_freqpoly <-
122124
aes(color = "ypred"),
123125
linewidth = 0.5,
124126
na.rm = TRUE,
125-
binwidth = binwidth
127+
binwidth = binwidth,
128+
bins = bins
126129
) +
127130
scale_color_ppd(
128131
name = stat_legend_title(stat, deparse(substitute(stat))),
@@ -146,6 +149,7 @@ ppd_stat_freqpoly_grouped <-
146149
...,
147150
facet_args = list(),
148151
binwidth = NULL,
152+
bins = NULL,
149153
freq = TRUE) {
150154
check_ignored_arguments(...)
151155
call <- match.call(expand.dots = FALSE)

man/MCMC-nuts.Rd

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

man/MCMC-scatterplots.Rd

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

man/PPC-distributions.Rd

Lines changed: 11 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)