Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bins and breaks arguments to more histogram and hex plots #313

Merged
merged 1 commit into from
Jan 18, 2024
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
25 changes: 18 additions & 7 deletions R/mcmc-diagnostics-nuts.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,16 @@ NULL

#' @rdname MCMC-nuts
#' @export
#' @param binwidth An optional value passed to [ggplot2::geom_histogram()] to
#' override the default binwidth.
#' @template args-hist
#'
mcmc_nuts_acceptance <-
function(x,
lp,
chain = NULL,
...,
binwidth = NULL) {
binwidth = NULL,
bins = NULL,
breaks = NULL) {
suggested_package("gridExtra")
check_ignored_arguments(...)

Expand All @@ -160,7 +161,9 @@ mcmc_nuts_acceptance <-
color = get_color("lh"),
linewidth = 0.25,
na.rm = TRUE,
binwidth = binwidth
binwidth = binwidth,
bins = bins,
breaks = breaks
) +
bayesplot_theme_get()

Expand Down Expand Up @@ -209,7 +212,9 @@ mcmc_nuts_acceptance <-
color = NA,
alpha = 0.5,
na.rm = TRUE,
binwidth = binwidth
binwidth = binwidth,
bins = bins,
breaks = breaks
)

chain_scatter_data <- data.frame(
Expand Down Expand Up @@ -417,6 +422,8 @@ mcmc_nuts_energy <-
function(x,
...,
binwidth = NULL,
bins = NULL,
breaks = NULL,
alpha = 0.5,
merge_chains = FALSE) {
check_ignored_arguments(...)
Expand Down Expand Up @@ -446,7 +453,9 @@ mcmc_nuts_energy <-
),
linewidth = 0.25,
na.rm = TRUE,
binwidth = binwidth
binwidth = binwidth,
bins = bins,
breaks = breaks
) +
geom_histogram(
aes(
Expand All @@ -457,7 +466,9 @@ mcmc_nuts_energy <-
linewidth = 0.25,
na.rm = TRUE,
alpha = alpha,
binwidth = binwidth
binwidth = binwidth,
bins = bins,
breaks = breaks
) +
scale_fill_manual("", values = fills, labels = aes_labs) +
scale_color_manual("", values = clrs, labels = aes_labs) +
Expand Down
6 changes: 5 additions & 1 deletion R/mcmc-scatterplots.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @param ... Currently ignored.
#' @param size,alpha For `mcmc_scatter()`, passed to
#' [ggplot2::geom_point()] to control the appearance of the points.
#' @param binwidth For `mcmc_hex()`, an optional numeric vector of
#' @param bins,binwidth For `mcmc_hex()`, an optional numeric vector of
#' *length two* passed to [ggplot2::geom_hex()] to override the
#' default binwidth in both the vertical and horizontal directions.
#'
Expand Down Expand Up @@ -156,6 +156,7 @@ mcmc_hex <- function(x,
regex_pars = character(),
transformations = list(),
...,
bins = 30,
binwidth = NULL) {
suggested_package("scales")
suggested_package("hexbin")
Expand All @@ -166,6 +167,7 @@ mcmc_hex <- function(x,
regex_pars = regex_pars,
transformations = transformations,
hex = TRUE,
bins = bins,
binwidth = binwidth,
size = NULL,
alpha = NULL
Expand Down Expand Up @@ -641,6 +643,7 @@ pairs_condition <- function(chains = NULL, draws = NULL, nuts = NULL) {
hex = FALSE,
size = 2.5,
alpha = 0.8,
bins = 30,
binwidth = NULL,
np = NULL,
np_style = scatter_style_np()) {
Expand Down Expand Up @@ -702,6 +705,7 @@ pairs_condition <- function(chains = NULL, draws = NULL, nuts = NULL) {
graph <- graph +
geom_hex(
aes(fill = scales::rescale(after_stat(density))),
bins = bins,
binwidth = binwidth
) +
scale_fill_gradientn(
Expand Down
3 changes: 3 additions & 0 deletions R/ppc-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ ppc_freqpoly <-
yrep,
...,
binwidth = NULL,
bins = NULL,
freq = TRUE,
size = 0.5,
alpha = 1) {
Expand All @@ -420,6 +421,7 @@ ppc_freqpoly <-
geom_area(
stat = "bin",
binwidth = binwidth,
bins = bins,
linewidth = size,
alpha = alpha
) +
Expand All @@ -446,6 +448,7 @@ ppc_freqpoly_grouped <-
group,
...,
binwidth = NULL,
bins = NULL,
freq = TRUE,
size = 0.5,
alpha = 1) {
Expand Down
1 change: 1 addition & 0 deletions R/ppc-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ ppc_error_hist_grouped <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
breaks = NULL,
freq = TRUE) {

Expand Down
6 changes: 5 additions & 1 deletion R/ppc-test-statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ ppc_stat_grouped <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
breaks = NULL,
freq = TRUE) {
check_ignored_arguments(...)
Expand All @@ -185,6 +186,7 @@ ppc_stat_freqpoly <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
freq = TRUE) {
stopifnot(length(stat) == 1)
dots <- list(...)
Expand All @@ -208,7 +210,8 @@ ppc_stat_freqpoly <-
aes(color = "yrep"),
linewidth = 0.5,
na.rm = TRUE,
binwidth = binwidth
binwidth = binwidth,
bins = bins
) +
geom_vline(
data = dplyr::filter(data, .data$variable == "y"),
Expand Down Expand Up @@ -240,6 +243,7 @@ ppc_stat_freqpoly_grouped <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
freq = TRUE) {
check_ignored_arguments(...)
call <- match.call(expand.dots = FALSE)
Expand Down
3 changes: 3 additions & 0 deletions R/ppd-distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ ppd_freqpoly <-
function(ypred,
...,
binwidth = NULL,
bins = NULL,
freq = TRUE,
size = 0.5,
alpha = 1) {
Expand All @@ -213,6 +214,7 @@ ppd_freqpoly <-
geom_area(
stat = "bin",
binwidth = binwidth,
bins = bins,
size = size,
alpha = alpha
) +
Expand All @@ -238,6 +240,7 @@ ppd_freqpoly_grouped <-
group,
...,
binwidth = NULL,
bins = NULL,
freq = TRUE,
size = 0.5,
alpha = 1) {
Expand Down
6 changes: 5 additions & 1 deletion R/ppd-test-statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ppd_stat_grouped <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
breaks = NULL,
freq = TRUE) {
check_ignored_arguments(...)
Expand All @@ -104,6 +105,7 @@ ppd_stat_freqpoly <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
freq = TRUE) {
stopifnot(length(stat) == 1)
dots <- list(...)
Expand All @@ -122,7 +124,8 @@ ppd_stat_freqpoly <-
aes(color = "ypred"),
linewidth = 0.5,
na.rm = TRUE,
binwidth = binwidth
binwidth = binwidth,
bins = bins
) +
scale_color_ppd(
name = stat_legend_title(stat, deparse(substitute(stat))),
Expand All @@ -146,6 +149,7 @@ ppd_stat_freqpoly_grouped <-
...,
facet_args = list(),
binwidth = NULL,
bins = NULL,
freq = TRUE) {
check_ignored_arguments(...)
call <- match.call(expand.dots = FALSE)
Expand Down
30 changes: 26 additions & 4 deletions man/MCMC-nuts.Rd

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

3 changes: 2 additions & 1 deletion man/MCMC-scatterplots.Rd

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

12 changes: 11 additions & 1 deletion man/PPC-distributions.Rd

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

1 change: 1 addition & 0 deletions man/PPC-errors.Rd

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

3 changes: 3 additions & 0 deletions man/PPC-test-statistics.Rd

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

11 changes: 10 additions & 1 deletion man/PPD-distributions.Rd

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

Loading
Loading