Skip to content

Commit 580b55c

Browse files
committed
Merge branch 'ggplotly' of github.com:ropensci/plotly into ggplotly
Use ggplotly branch as a 'stage' branch (following Toby's practices).
2 parents bfdabca + c5e1594 commit 580b55c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

inst/tests/test-ggplot-bar.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
context("bar")
2+
3+
researchers <-
4+
data.frame(country=c("Canada", "Canada", "Germany", "USA"),
5+
name=c("Warren", "Andreanne", "Stefan", "Toby"),
6+
papers=c(23, 14, 37, 20),
7+
field=c("Math", "Bio", "Bio", "Math"))
8+
9+
gg <- ggplot(researchers, aes(country, papers, fill=field))
10+
11+
test_that("position_dodge is translated to barmode=group", {
12+
gg.dodge <- gg+geom_bar(stat="identity", position="dodge")
13+
L <- gg2list(gg.dodge)
14+
expect_equal(length(L), 3)
15+
trace.names <- sapply(L[1:2], "[[", "name")
16+
expect_true(all(c("Math", "Bio") %in% trace.names))
17+
expect_identical(L$kwargs$layout$barmode, "group")
18+
})
19+
20+
test_that("position_stack is translated to barmode=stack", {
21+
gg.stack <- gg+geom_bar(stat="identity", position="stack")
22+
gg2list(gg.stack)
23+
expect_equal(length(L), 3)
24+
trace.names <- sapply(L[1:2], "[[", "name")
25+
expect_true(all(c("Math", "Bio") %in% trace.names))
26+
expect_identical(L$kwargs$layout$barmode, "stack")
27+
})
28+
29+
test_that("position_identity is translated to barmode=overlay", {
30+
gg.identity <- gg+geom_bar(stat="identity", position="identity")
31+
gg2list(gg.identity)
32+
expect_equal(length(L), 3)
33+
trace.names <- sapply(L[1:2], "[[", "name")
34+
expect_true(all(c("Math", "Bio") %in% trace.names))
35+
expect_identical(L$kwargs$layout$barmode, "overlay")
36+
})
37+

0 commit comments

Comments
 (0)