-
Notifications
You must be signed in to change notification settings - Fork 633
/
Copy pathtest-ggplot-bar.R
36 lines (31 loc) · 1.3 KB
/
test-ggplot-bar.R
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
32
33
34
35
36
context("bar")
researchers <-
data.frame(country=c("Canada", "Canada", "Germany", "USA"),
name=c("Warren", "Andreanne", "Stefan", "Toby"),
papers=c(23, 14, 37, 20),
field=c("Math", "Bio", "Bio", "Math"))
gg <- ggplot(researchers, aes(country, papers, fill=field))
test_that("position_dodge is translated to barmode=group", {
gg.dodge <- gg + geom_bar(stat="identity", position="dodge")
L <- gg2list(gg.dodge)
expect_equal(length(L), 3)
trace.names <- sapply(L[1:2], "[[", "name")
expect_true(all(c("Math", "Bio") %in% trace.names))
expect_identical(L$kwargs$layout$barmode, "group")
})
test_that("position_stack is translated to barmode=stack", {
gg.stack <- gg + geom_bar(stat="identity", position="stack")
L <- gg2list(gg.stack)
expect_equal(length(L), 3)
trace.names <- sapply(L[1:2], "[[", "name")
expect_true(all(c("Math", "Bio") %in% trace.names))
expect_identical(L$kwargs$layout$barmode, "stack")
})
test_that("position_identity is translated to barmode=overlay", {
gg.identity <- gg + geom_bar(stat="identity", position="identity")
L <- gg2list(gg.identity)
expect_equal(length(L), 3)
trace.names <- sapply(L[1:2], "[[", "name")
expect_true(all(c("Math", "Bio") %in% trace.names))
expect_identical(L$kwargs$layout$barmode, "overlay")
})