Skip to content

Commit 6aef18c

Browse files
committed
dont try to merge identical bar traces, fixes #250
1 parent d7a340c commit 6aef18c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

R/ggplotly.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ gg2list <- function(p) {
851851
tr.attr <- tr[[must.be.equal]]
852852
criteria[[must.be.equal]] <- isTRUE(all.equal(other.attr, tr.attr))
853853
}
854-
if(all(criteria)){
854+
if(all(criteria) && tr$type != "bar"){
855855
can.merge[[other.i]] <- TRUE
856856
}
857857
}

tests/testthat/test-ggplot-stack.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,19 @@ test_that("y value is non-cumulative in stacked bar charts", {
2121
expect_equal(L$data[[2]]$y[2], instructors$number[5])
2222
expect_equal(L$data[[3]]$y[2], instructors$number[6])
2323
})
24+
25+
testd <- data.frame(
26+
group1 = rep(1:3, each = 3),
27+
group2 = LETTERS[1:3],
28+
# We have two 0.2 within each group.
29+
count = c(0.2, 0.2, 0.6)
30+
)
31+
32+
test_that("can stack identical traces", {
33+
p1 <- ggplot(testd, aes(x = factor(group1), y = count,
34+
fill = factor(group2))) +
35+
geom_bar(stat = 'identity', width = 1, position = "stack")
36+
L <- save_outputs(p1, "stack-identical")
37+
expect_equal(length(L$data), 3)
38+
})
39+

0 commit comments

Comments
 (0)