library(bayesplot)
## This is bayesplot version 1.6.0
## - Online documentation and vignettes at mc-stan.org/bayesplot
## - bayesplot theme set to bayesplot::theme_default()
##    * Does _not_ affect other ggplot2 plots
##    * See ?bayesplot_theme_set for details on theme setting
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)

example_data <- bayesplot::example_mcmc_draws(params = 6)

d <- mcmc_areas_data(example_data, c("beta[1]", "beta[2]", "beta[3]")) %>%
  mutate(
    interval = factor(interval, c("outer", "inner", "point")))

# rescale density within each parameter to be proportion of max density
d <- d %>%
  group_by(parameter) %>%
  mutate(scaled = density / max(density)) %>%
  ungroup()


ggplot(d) +
  aes(x = x, y = parameter, fill = interval, height = scaled) +
  ggridges::geom_density_ridges(
    stat = "identity",
    scale = 0.90) +
  scale_fill_brewer(type = "seq", palette = 2) +
  guides(fill = FALSE) +
  scale_y_discrete(
    limits = unique(rev(d$parameter)),
    expand = expand_scale(mult = c(.05, .5))) +
  ggtitle("curves have same height")

ggplot(d) +
  aes(x = x, y = parameter, fill = interval, height = density) +
  ggridges::geom_density_ridges(stat = "identity", scale = 0.90) +
  scale_fill_brewer(type = "seq", palette = 2) +
  guides(fill = FALSE) +
  ggtitle("curves have same area") +
  scale_y_discrete(
    limits = unique(rev(d$parameter)),
    expand = expand_scale(mult = c(.05, .5)))