Skip to content

Commit c610e8e

Browse files
committed
add test
1 parent 0e67a33 commit c610e8e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/testthat/test-position-jitter.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test_that("automatic jitter width considers panels", {
2+
3+
df <- data.frame(x = c(1, 2, 100, 200), f = c("A", "A", "B", "B"))
4+
5+
auto <- position_jitter(seed = 0)
6+
fixed <- position_jitter(seed = 0, width = 0.5)
7+
8+
p <- ggplot(df, aes(x, 1)) + facet_wrap(vars(f))
9+
10+
fixed <- layer_data(p + geom_point(position = fixed))$x - df$x
11+
auto <- layer_data(p + geom_point(position = auto))$x - df$x
12+
13+
# Magic number 0.4 comes from default resolution multiplier
14+
expect_equal(fixed / 0.5, auto / c(0.4, 0.4, 40, 40))
15+
})

0 commit comments

Comments
 (0)