tests/testthat/test-position_stack.R

library(ggplot2)

common_bw <- 1.5

# note: base ggplot doesn't seem to set the same bandwith for different
# data `group`s

test_that("P(A,B), equiv to using position=stack", {

  skip_if_not_installed("vdiffr")
  skip_if_not_installed("svglite")

  base_ggplot <- ggplot(mtcars) +
    geom_density(aes(x = mpg, y = ..count..,
                     fill = factor(cyl)), position = "stack",
                 bw = common_bw)
  vdiffr::expect_doppelganger("ggplot2 stacked density", base_ggplot)

  pgog_stacked <-
    ggplot(mtcars) +
    geom_bloc(aes(
      x = c(mpg),
      height = c(P(cyl|mpg), P(mpg)),
      fill = factor(cyl)), bw = common_bw)

  vdiffr::expect_doppelganger("pgog stacked density", pgog_stacked)
})
hdi-lab/uncertainty-gog documentation built on Nov. 14, 2021, 5:15 p.m.