-
-
Notifications
You must be signed in to change notification settings - Fork 89
Remove unnecessary y-axis from MCMC density and histogram plots #420
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,9 +67,11 @@ | |
| #' } | ||
| #' # example of using 'transformations' argument to plot log(sigma), | ||
| #' # and parsing facet labels (e.g. to get greek letters for parameters) | ||
| #' mcmc_hist(x, transformations = list(sigma = "log"), | ||
| #' facet_args = list(labeller = ggplot2::label_parsed)) + | ||
| #' facet_text(size = 15) | ||
| #' mcmc_hist(x, | ||
| #' transformations = list(sigma = "log"), | ||
| #' facet_args = list(labeller = ggplot2::label_parsed) | ||
| #' ) + | ||
| #' facet_text(size = 15) | ||
| #' \donttest{ | ||
| #' # instead of list(sigma = "log"), you could specify the transformation as | ||
| #' # list(sigma = log) or list(sigma = function(x) log(x)), but then the | ||
|
|
@@ -85,14 +87,18 @@ | |
| #' ### Densities ### | ||
| #' ################# | ||
| #' | ||
| #' mcmc_dens(x, pars = c("sigma", "beta[2]"), | ||
| #' facet_args = list(nrow = 2)) | ||
| #' mcmc_dens(x, | ||
| #' pars = c("sigma", "beta[2]"), | ||
| #' facet_args = list(nrow = 2) | ||
| #' ) | ||
| #' \donttest{ | ||
| #' # separate and overlay chains | ||
| #' color_scheme_set("mix-teal-pink") | ||
| #' mcmc_dens_overlay(x, pars = c("sigma", "beta[2]"), | ||
| #' facet_args = list(nrow = 2)) + | ||
| #' facet_text(size = 14) | ||
| #' mcmc_dens_overlay(x, | ||
| #' pars = c("sigma", "beta[2]"), | ||
| #' facet_args = list(nrow = 2) | ||
| #' ) + | ||
| #' facet_text(size = 14) | ||
| #' x2 <- example_mcmc_draws(params = 6) | ||
| #' mcmc_dens_chains(x2, pars = c("beta[1]", "beta[2]", "beta[3]")) | ||
| #' } | ||
|
|
@@ -170,7 +176,10 @@ mcmc_dens <- function( | |
| bounds = bounds, | ||
| alpha = alpha, | ||
| ... | ||
| ) | ||
| ) + | ||
| yaxis_text(FALSE) + | ||
| yaxis_title(FALSE) + | ||
| yaxis_ticks(FALSE) | ||
| } | ||
|
|
||
| #' @rdname MCMC-distributions | ||
|
|
@@ -237,7 +246,10 @@ mcmc_dens_overlay <- function( | |
| n_dens = n_dens, | ||
| bounds = bounds, | ||
| ... | ||
| ) | ||
| ) + | ||
| yaxis_text(FALSE) + | ||
| yaxis_title(FALSE) + | ||
| yaxis_ticks(FALSE) | ||
|
Comment on lines
+250
to
+252
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are already included in the internal |
||
| } | ||
|
|
||
| #' @rdname MCMC-distributions | ||
|
|
@@ -281,7 +293,8 @@ mcmc_dens_chains <- function( | |
| } else { | ||
| scale_color <- scale_color_manual( | ||
| values = rep(get_color("m"), n_chains), | ||
| guide = "none") | ||
| guide = "none" | ||
| ) | ||
| } | ||
|
|
||
| ggplot(data) + | ||
|
|
@@ -371,9 +384,6 @@ mcmc_violin <- function( | |
| ) | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
| # internal ----------------------------------------------------------------- | ||
| .mcmc_hist <- function( | ||
| x, | ||
|
|
@@ -398,7 +408,7 @@ mcmc_violin <- function( | |
| data <- melt_mcmc(x, value.name = "value") | ||
| n_param <- num_params(data) | ||
|
|
||
| graph <- ggplot(data, aes(x = ~ value)) + | ||
| graph <- ggplot(data, aes(x = ~value)) + | ||
| geom_histogram( | ||
| set_hist_aes(freq), | ||
| fill = get_color("mid"), | ||
|
|
@@ -450,16 +460,15 @@ mcmc_violin <- function( | |
| color_chains = FALSE, | ||
| geom = c("density", "violin"), | ||
| probs = c(0.1, 0.5, 0.9), | ||
| trim = FALSE, | ||
| alpha = 1, | ||
| bw = NULL, | ||
| adjust = NULL, | ||
| kernel = NULL, | ||
| n_dens = NULL, | ||
| bounds = NULL, | ||
| ... | ||
| ) { | ||
|
|
||
| trim = FALSE, | ||
| alpha = 1, | ||
| bw = NULL, | ||
| adjust = NULL, | ||
| kernel = NULL, | ||
| n_dens = NULL, | ||
| bounds = NULL, | ||
| ... | ||
| ) { | ||
| bw <- bw %||% "nrd0" | ||
| adjust <- adjust %||% 1 | ||
| kernel <- kernel %||% "gaussian" | ||
|
|
@@ -534,16 +543,19 @@ mcmc_violin <- function( | |
| } else { | ||
| scale_color <- scale_color_manual( | ||
| values = rep(get_color("m"), n_chains), | ||
| guide = "none") | ||
| guide = "none" | ||
| ) | ||
| } | ||
| graph <- graph + scale_color | ||
| } | ||
|
|
||
| if (n_param == 1) { | ||
| graph <- | ||
| graph + | ||
| labs(x = if (violin) "Chain" else levels(data$Parameter), | ||
| y = if (violin) levels(data$Parameter) else NULL) | ||
| labs( | ||
| x = if (violin) "Chain" else levels(data$Parameter), | ||
| y = if (violin) levels(data$Parameter) else NULL | ||
| ) | ||
| } else { | ||
| facet_args[["facets"]] <- vars(.data$Parameter) | ||
| facet_args[["scales"]] <- facet_args[["scales"]] %||% "free" | ||
|
|
@@ -555,6 +567,6 @@ mcmc_violin <- function( | |
| bayesplot_theme_get() + | ||
| yaxis_text(FALSE) + | ||
| yaxis_ticks(FALSE) + | ||
| yaxis_title(on = n_param == 1 && violin) + | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to keep this for the special case of 1 parameter and a violin plot. If you look at a 1 parameter violin plot you'll see why (the y-axis provides the parameter name) |
||
| yaxis_title(FALSE) + | ||
| xaxis_title(on = n_param == 1) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are already included in the internal
.mcmc_dens()function so we don't need to add them again here. These don't turn off the y-axis, they just turn off the text and tick marks, but those were already off.