File: test-ggalluvial.R

package info (click to toggle)
r-cran-plotly 4.10.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,636 kB
  • sloc: javascript: 195,272; sh: 24; makefile: 6
file content (31 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
skip_if_not_installed("ggalluvial")
library(ggalluvial)

test_that("using both of `geom_alluvium` and `geom_stratum` gives the correct output", {
  p <- ggplot(as.data.frame(Titanic),
              aes(y = Freq, axis1 = Survived, axis2 = Sex, axis3 = Class)) +
    geom_alluvium(aes(fill = Class),
                  width = 0, knot.pos = 0, reverse = FALSE) +
    guides(fill = "none") +
    geom_stratum(width = 1/8, reverse = FALSE) +
    geom_text(stat = "stratum", aes(label = after_stat(stratum)),
              reverse = FALSE) +
    scale_x_continuous(breaks = 1:3, labels = c("Survived", "Sex", "Class")) +
    coord_flip() +
    ggtitle("Titanic survival by class and sex")
  expect_doppelganger(ggplotly(p), "stratum-alluvium")
})

test_that("color aesthetic works", {
  p <- ggplot(as.data.frame(Titanic),
              aes(y = Freq, axis1 = Survived, axis2 = Sex, axis3 = Class)) +
    geom_alluvium(aes(color = Class), width = 0, knot.pos = 0, reverse = FALSE, alpha = 0.3) +
    geom_stratum(width = 1/8, reverse = FALSE) +
    geom_text(stat = "stratum", aes(label = after_stat(stratum)),
              reverse = FALSE) +
    scale_x_continuous(breaks = 1:3, labels = c("Survived", "Sex", "Class")) +
    coord_flip() +
    ggtitle("Titanic survival by class and sex")
  expect_doppelganger(ggplotly(p), "stratum-alluvium-color")
})