-
-
Notifications
You must be signed in to change notification settings - Fork 82
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 bayesplot_theme_*() functions and remove startup theme_set() #149
Conversation
Closes stan-dev#257 Reflects changes to `bayesplot` approach to themes in stan-dev/bayesplot#149
Codecov Report
@@ Coverage Diff @@
## master #149 +/- ##
==========================================
- Coverage 98.79% 98.55% -0.24%
==========================================
Files 30 30
Lines 3891 3952 +61
==========================================
+ Hits 3844 3895 +51
- Misses 47 57 +10
Continue to review full report at Codecov.
|
@malcolmbarrett Thanks so much for working on this! We'll go through and review it as soon as possible. |
In the final case, the bayesplot is still using the dark theme. library(bayesplot)
library(ggplot2)
# plot using the default theme automatically
x <- example_mcmc_draws()
mcmc_hist(x)
# change theme for all ggplots
theme_set(theme_dark())
mcmc_hist(x)
# change back to the default
bayesplot_theme_set(theme_default())
mcmc_hist(x) |
In
We should apply the bayesplot theme earlier so that the theming works. We should also limit/cut back on this kind of by-plot theming and document any custom-theming (that can be its own issue). (I think there are good uses for by-plot theming, like in the ridgeline plots where it's good have horizontal lines and to align the axis labels above the tick marks.) |
@tjmahr that example isn't in the docs, right? In that case, setting Regarding your second comment: I shuffled the theme calls around so they are now in the correct order. |
I'm thinking more in terms of the code working as expected... |
When you put it that way, I think you're absolutely right. Try this. It should work the way you describe. The only case I can come up with where it's not totally in order is something like this: # change all themes
theme_set(theme_dark())
mcmc_hist(x)
# change back to the default
bayesplot_theme_set(theme_default())
mcmc_hist(x)
# try to change all themes again to the same theme as above
theme_set(theme_dark())
mcmc_hist(x) # still theme_default()
# but setting a new theme works:
theme_set(theme_minimal())
mcmc_hist(x) # theme_minimal() This is because it now saves the existing ggplot2 |
@malcolmbarrett Thanks again for this PR! I haven't had a chance to run the code yet (will do soon), but some quick comments:
I actually don't think it's that strange but that may be because I've seen every single bayesplot plot many many times. Some of them aren't as easily readable if certain kinds of themes are set. So I actually think there can be a good reason for maintaining a separate theme for bayesplot, although most plots will be fine regardless of the theme. @tjmahr I also definitely agree with both of these other items you mentioned:
|
I know it would be slightly different behavior than |
Ok, I'm convinced! Try out the solution I committed above and see what you think.
Makes sense to me! Just added. |
@malcolmbarrett Thanks for adding the default. I just made a few minor tweaks to the doc and some internal code, but looks good! @tjmahr Any else you think should be changed before we merge this? |
@tjmahr sounds good (and no rush if you’re super busy at the moment) |
#' mcmc_dens_overlay(x) | ||
#' | ||
bayesplot_theme_get <- function() { | ||
if (!identical(.bayesplot_theme_env$gg_current, ggplot2::theme_get())) { |
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.
This is cool
@@ -262,14 +264,16 @@ mcmc_nuts_divergence <- function(x, lp, chain = NULL, ...) { | |||
violin_lp <- ggplot(violin_lp_data, aes_(x = ~ Value, y = ~ lp)) + | |||
geom_violin(fill = get_color("l"), color = get_color("lh")) + | |||
ylab("lp__") + | |||
xaxis_title(FALSE) | |||
xaxis_title(FALSE) + | |||
bayesplot_theme_get() |
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.
I had thought that bayesplot_theme_get()
would override the change by xaxis_title()
because xaxis_title()
can theme xaxis titles. But xaxis_title(FALSE)
just calls labs()
so these are all fine.
Just double checking, are we ready to finally merge this? |
I think so! |
Add @malcolmbarrett to DESCRIPTION file as a contributor and add these changes to the NEWS file.
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.
@malcolmbarrett Thanks again for doing this. Finally merging!
Closes #117
This PR adds
bayesplot_theme_set()
,bayesplot_theme_get()
,bayesplot_theme_update()
, andbayesplot_theme_replace()
, which apply only tobayesplot
s. The user can change the themes applied tobayesplot
using these functions, which are now the default for all plotting functions.bayesplot
no longer changes the defaultggplot2
theme, instead using this internal approach, andbayesplot_theme_*()
functions do not affect otherggplot
s.The
ggplot2
equivalents supersede these. Loadingggplot2
will not affectbayesplot
themes, but explicitly calling e.g.theme_set(theme_minimal())
will change allggplot
s, includingbayesplot
s, totheme_minimal()
. I believe that this is the functionality most people would want, but this is done with a single line of code checking if theggplot2
theme is set to anything other thantheme_grey()
(the default) and can easily be removed.