To reverse the colors in an existing color scheme, you can use the rev
(“reverse”) function to reverse the color order in bayesplot’s color scheme.
color_scheme_get()
gives the current color scheme. If we look at the structure of the color scheme object, we can see that creating a scheme with a reversed color order should invert the colors in the plot.
library(bayesplot)
> str(color_scheme_get())
List of 6
$ light : chr "#d1e1ec"
$ light_highlight: chr "#b3cde0"
$ mid : chr "#6497b1"
$ mid_highlight : chr "#005b96"
$ dark : chr "#03396c"
$ dark_highlight : chr "#011f4b"
- attr(*, "mixed")= logi FALSE
- attr(*, "scheme_name")= chr "blue"
- attr(*, "class")= chr [1:2] "bayesplot_scheme" "list"
Here’s an example:
# some parameter draws to use for demonstration
set.seed(3)
x <- example_mcmc_draws(params = 4)
color_scheme_set("red")
mcmc_areas(x, regex_pars="beta")
Now reverse the colors in the color scheme:
cols = rev(unname(unlist(color_scheme_get())))
color_scheme_set(cols)
mcmc_areas(x, regex_pars="beta")
You can also set your own custom color scheme by creating a vector of six colors. Below I’ve just reversed the custom color vector from the help for bayesplot-colors
.
orange_scheme <- rev(c("#ffebcc", "#ffcc80",
"#ffad33", "#e68a00",
"#995c00", "#663d00"))
color_scheme_set(orange_scheme)
mcmc_areas(x, regex_pars="beta")
Created on 2022-03-24 by the reprex package (v2.0.1)