infer annotation aesthetics from global theme
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 442
- Forks
- 93
- Avg merge
- 3h 11m
- Merged PRs (30d)
- 1
Description
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)

That vertical line doesn't play well with other themes.
theme_set(theme_grey())
mcmc_intervals(x)

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)

Otherwise it goes twice the width of the major gridlines.
theme_set(theme_grey())
mcmc_intervals(x)

And generalize to any other gridlined theme.
theme_set(ggthemes::theme_solarized())
mcmc_intervals(x)

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at mcmc_intervals() and the layer_vertical_line block shown in the issue; inspect how vline_0() receives its color and size. Check the theme_get() values and fallback behavior described in the proposal. Done means the zero line follows the active theme's gridline styling across the shown themes without appearing when zero is outside the limits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100