Skip to content

infer annotation aesthetics from global theme #120

Open
@tjmahr

Description

@tjmahr

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions