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

infer annotation aesthetics from global theme #120

Open
tjmahr opened this issue Sep 27, 2017 · 3 comments
Open

infer annotation aesthetics from global theme #120

tjmahr opened this issue Sep 27, 2017 · 3 comments

Comments

@tjmahr
Copy link
Collaborator

tjmahr commented Sep 27, 2017

I was thinking today about how mcmc_intervals() draws a vertical line if the x's contain 0.

library(bayesplot)
library(ggplot2)
x <- example_mcmc_draws()
mcmc_intervals(x)

image

That vertical line doesn't play well with other themes.

theme_set(theme_grey())
mcmc_intervals(x)

image

That line color is hard-coded... Specifically in this code.

# faint vertical line at zero if zero is within x_lim
layer_vertical_line <- if (0 > x_lim[1] && 0 < x_lim[2]) {
  vline_0(color = "gray90", size = 0.5)
} else {
  geom_ignore()
}

But in principle, we could just borrow theme's current gridline color and fatten it.

layer_vertical_line <- if (0 > x_lim[1] && 0 < x_lim[2]) {
  # this would change to `theme_bayesplot_get()` if go that route in 
  # issue 117
  t <- theme_get()
  # `x %||% y` returns y when x is NULL and x otherwise
  color <- t$panel.grid.major$colour %||% "grey92"
  minor_size <- t$panel.grid.minor$size %||% .125
  major_size <- t$panel.grid.major$size %||% (minor_size * 2)
  size <- major_size * 2
  vline_0(color = color, size = size)
} else {
  geom_ignore()
}

When there are no gridlines, it would default to .5.

theme_set(theme_default())
mcmc_intervals(x)

image

Otherwise it goes twice the width of the major gridlines.

theme_set(theme_grey())
mcmc_intervals(x)

image

And generalize to any other gridlined theme.

theme_set(ggthemes::theme_solarized())
mcmc_intervals(x)

image

@jgabry
Copy link
Member

jgabry commented Nov 7, 2017

I see what you mean about the line not playing well with other themes. This this seems like a good solution.

@tjmahr
Copy link
Collaborator Author

tjmahr commented May 3, 2019

Let's wait and see what happens here tidyverse/ggplot2#2749 where the ggplot2 authors are sorting out how to make default aesthetics customizable with a plotting theme.

@jgabry
Copy link
Member

jgabry commented May 5, 2019

Thanks for the link. If they add that functionality to ggplot2 we should definitely have it play nicely with bayesplot, which would also take care of this early issue I had forgotten about,#45, regarding setting more plotting defaults.

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

No branches or pull requests

2 participants