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

mcmc_pairs() + plot_bg() yields a NULL #128

Closed
ASKurz opened this issue Nov 18, 2017 · 4 comments
Closed

mcmc_pairs() + plot_bg() yields a NULL #128

ASKurz opened this issue Nov 18, 2017 · 4 comments
Labels

Comments

@ASKurz
Copy link

ASKurz commented Nov 18, 2017

I have a handful of posterior parameters I’d like to put in a pairs plot. By itself, mcmc_pairs() works great. E.g.,

posterior <- tibble(x = rnorm(1e3, 0, 1),
                    y = rnorm(1e3, 0, 1),
                    z = rnorm(1e3, 0, 1))
                    
mcmc_pairs(x = posterior,
           pars = c("x", "y", "z"))

I’d like to change my background fill. But when I try to use plot_bg(), I get a NULL.

mcmc_pairs(x = posterior,
           pars = c("x", "y", "z")) +
  plot_bg(fill = "grey85",
          color = "transparent")

Yet, plot_bg() works just fine with mcmc_scatter(). E.g.,

mcmc_scatter(x = posterior,
             pars = c("x", "y")) +
  plot_bg(fill = "grey85",
          color = "transparent")

What am I missing?

@jgabry
Copy link
Member

jgabry commented Nov 18, 2017

I think this is because mcmc_pairs unfortunately returns a grid of different ggplot objects plots instead of a single ggplot object (almost all of the other functions return a single ggplot object). It wasn't possible (at least it didn't seem possible when we tried) to get the plot how we wanted it to look without creating separate plots and combining them in a grid like that.

To get around this problem you can try updating the theme before making the plot, e.g:

library(bayesplot)
library(ggplot2)

# set theme to default bayesplot theme but modify background
my_background <- element_rect(fill = "grey85", color = "transparent") 
theme_set(theme_default() + theme(plot.background = my_background))

# then call mcmc_pairs after updating the theme
mcmc_pairs(...)

Does that make the plot you were wanting?

@jgabry
Copy link
Member

jgabry commented Nov 18, 2017

Actually you can just do

theme_set(theme_default() + plot_bg(fill = "grey85", color = "transparent"))

@ASKurz
Copy link
Author

ASKurz commented Nov 18, 2017

That’s instructive. Yes, both methods work great. Thanks jgabry!

@jgabry
Copy link
Member

jgabry commented Nov 18, 2017

No problem, glad that worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants