bayesplot (version 1.6.0)

bayesplot-colors: Set, get, or view color schemes

Description

Set, get, or view color schemes. Choose from a preset scheme or create a custom scheme.

Usage

color_scheme_set(scheme = "blue")

color_scheme_get(scheme, i)

color_scheme_view(scheme)

Arguments

scheme

For color_scheme_set, either a string naming one of the available color schemes or a character vector of exactly six colors specifying a custom scheme (see the Custom Color Schemes section, below, for more on specifying a custom scheme).

For color_scheme_get, scheme can be missing (to get the current color scheme) or a string naming one of the preset schemes.

For color_scheme_view, scheme can be missing (to use the current color scheme) or a character vector containing a subset of the available scheme names.

Currently, the available preset color schemes are:

  • "blue", "brightblue"

  • "gray", "darkgray"

  • "green"

  • "pink"

  • "purple"

  • "red"

  • "teal"

  • "yellow"

  • "viridis", "viridisA", "viridisB", "viridisC"

  • "mix-x-y", replacing x and y with any two of the scheme names listed above (e.g. "mix-teal-pink", "mix-blue-red", etc.). The order of x and y matters, i.e., the color schemes "mix-blue-red" and "mix-red-blue" are not identical. There is no guarantee that every possible mixed scheme will look good with every possible plot.

If you have a suggestion for a new color scheme please let us know via the bayesplot issue tracker.

i

For color_scheme_get, a subset of the integers from 1 (lightest) to 6 (darkest) indicating which of the colors in the scheme to return. If i is not specified then all six colors in the scheme are included.

Value

color_scheme_set has the side effect of setting the color scheme used for plotting. It also returns (invisibly) a list of the hexidecimal color values used in scheme.

color_scheme_get returns a list of the hexadecimal color values (without changing the current scheme). If the scheme argument is not specified the returned values correspond to the current color scheme. If the optional argument i is specified then the returned list only contains length(i) elements.

color_scheme_view returns a ggplot object if only a single scheme is specified and a gtable object if multiple schemes names are specified.

Custom Color Schemes

A bayesplot color scheme consists of six colors. To specify a custom color scheme simply pass a character vector containing either the names of six colors or six hexidecimal color values (or a mix of names and hex values). The colors should be in order from lightest to darkest. See the end of the Examples section for a demonstration.

See Also

theme_default for the default ggplot theme used by bayesplot.

Examples

Run this code
# NOT RUN {
color_scheme_set("blue")
color_scheme_view()

color_scheme_get()
color_scheme_get(i = c(3, 5)) # 3rd and 5th colors only

color_scheme_get("brightblue")
color_scheme_view("brightblue")

# compare multiple schemes
color_scheme_view(c("pink", "gray", "teal"))
color_scheme_view(c("viridis", "viridisA", "viridisB", "viridisC"))

color_scheme_set("pink")
x <- example_mcmc_draws()
mcmc_intervals(x)

color_scheme_set("teal")
color_scheme_view()
mcmc_intervals(x)

color_scheme_set("red")
mcmc_areas(x, regex_pars = "beta")

color_scheme_set("purple")
color_scheme_view()
y <- example_y_data()
yrep <- example_yrep_draws()
ppc_stat(y, yrep, stat = "mean") + legend_none()
# }
# NOT RUN {
color_scheme_set("mix-teal-pink")
ppc_stat(y, yrep, stat = "sd") + legend_none()
mcmc_areas(x, regex_pars = "beta")
# }
# NOT RUN {
###########################
### custom color scheme ###
###########################
orange_scheme <- c("#ffebcc", "#ffcc80",
                   "#ffad33", "#e68a00",
                   "#995c00", "#663d00")
color_scheme_set(orange_scheme)
mcmc_areas(x, regex_pars = "alpha")
mcmc_dens_overlay(x)
ppc_stat(y, yrep, stat = "var") + legend_none()

# }

Run the code above in your browser using DataLab