Skip to content

Commit ba04d89

Browse files
committed
debug cumulate + add test + update news - fix #146
1 parent 686b7bd commit ba04d89

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: ggalluvial
22
Type: Package
33
Title: Alluvial Plots in 'ggplot2'
4-
Version: 0.12.5
4+
Version: 0.12.5.0001
55
Authors@R: c(
66
person(given = "Jason Cory",
77
family = "Brunson",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The paramater `outline.type` from `ggplot2::geom_ribbon()` has been adapted to `
88

99
The tests that use the `Refugees` data set from **alluvial** are now only run if that package is installed; see #131 and thanks to @MichaelChirico.
1010

11+
## `cumulate()` fix
12+
13+
The `cumulate()` function previously broke if an axis had zero total alluvial height (#146); it has been debugged.
14+
1115
# ggalluvial 0.12.5
1216

1317
This patch fixes a bug involving the {dplyr} functions `first()` and `last()` that was shifted but not fixed in 0.12.4. Rather than being imported during build, they are accessed internally and thus imported during use. See issues #107 <https://github.com/corybrunson/ggalluvial/issues/107> and #108 <https://github.com/corybrunson/ggalluvial/issues/108> on GitHub for details.

R/stat-utils.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ deposit_data <- function(data, decreasing, reverse, absolute) {
9090
# calculate cumulative 'y' values, accounting for sign
9191
cumulate <- function(x) {
9292
if (length(x) == 0) return(x)
93+
if (all(x == 0)) return(rep(0, length(x)))
9394
s <- setdiff(unique(sign(x)), 0)
9495
stopifnot(length(s) == 1 && s %in% c(-1, 1))
9596
if (s == 1) {

tests/testthat/test-stat-alluvium.r

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,16 @@ test_that("`stat_flow` handles exceptional data with out errors", {
8888
geom_alluvium(aes(fill = country))
8989
expect_silent(ggplot_build(gg))
9090
})
91+
92+
d <- data.frame(
93+
subject = rep(c("A", "B"), each = 2),
94+
time = rep(1:2, times = 2),
95+
status = factor(c("a", "b", "b", "a")),
96+
value = c(0, 1, 0, 2)
97+
)
98+
test_that("`stat_alluvium` handles axes with zero total height", {
99+
gg <-
100+
ggplot(d, aes(x = time, stratum = status, alluvium = subject, y = value)) +
101+
stat_alluvium(aes(fill = subject))
102+
expect_silent(ggplot_build(gg))
103+
})

0 commit comments

Comments
 (0)