1
1
context(" position_nudge" )
2
2
3
3
test_that(" nudging works in both dimensions simultaneously" , {
4
+ # individual nudge value
4
5
df <- data_frame(x = 1 : 3 )
5
6
6
7
p <- ggplot(df , aes(x , x , xmax = x , xmin = x , ymax = x , ymin = x )) +
@@ -14,6 +15,22 @@ test_that("nudging works in both dimensions simultaneously", {
14
15
expect_equal(data $ y , 3 : 5 )
15
16
expect_equal(data $ ymin , 3 : 5 )
16
17
expect_equal(data $ ymax , 3 : 5 )
18
+
19
+ # multiple nudge values, including zero
20
+ df <- data_frame(x = c(1 , 2 , 1 ))
21
+
22
+ p <- ggplot(df , aes(x , x , xmax = x , xmin = x , ymax = x , ymin = x )) +
23
+ geom_point(position = position_nudge(x = c(0 , - 1 , 0 ), y = c(0 , 1 , 2 )))
24
+
25
+ data <- layer_data(p )
26
+
27
+ expect_equal(data $ x , c(1 , 1 , 1 ))
28
+ expect_equal(data $ xmin , c(1 , 1 , 1 ))
29
+ expect_equal(data $ xmax , c(1 , 1 , 1 ))
30
+ expect_equal(data $ y , c(1 , 3 , 3 ))
31
+ expect_equal(data $ ymin , c(1 , 3 , 3 ))
32
+ expect_equal(data $ ymax , c(1 , 3 , 3 ))
33
+
17
34
})
18
35
19
36
test_that(" nudging works in individual dimensions" , {
@@ -30,6 +47,17 @@ test_that("nudging works in individual dimensions", {
30
47
expect_equal(data $ xmin , 2 : 4 )
31
48
expect_equal(data $ xmax , 2 : 4 )
32
49
50
+ # multiple nudge values, including zero
51
+ p <- ggplot(df , aes(x = x , xmax = x , xmin = x )) +
52
+ layer(geom = Geom , stat = StatIdentity , position = position_nudge(x = c(0 , - 1 , - 2 )))
53
+
54
+ data <- layer_data(p )
55
+
56
+ expect_equal(data $ x , c(1 , 1 , 1 ))
57
+ expect_equal(data $ xmin , c(1 , 1 , 1 ))
58
+ expect_equal(data $ xmax , c(1 , 1 , 1 ))
59
+
60
+
33
61
# nudging in y
34
62
# use an empty layer so can test individual aesthetics
35
63
p <- ggplot(df , aes(y = x , ymax = x , ymin = x )) +
@@ -40,4 +68,15 @@ test_that("nudging works in individual dimensions", {
40
68
expect_equal(data $ y , 3 : 5 )
41
69
expect_equal(data $ ymin , 3 : 5 )
42
70
expect_equal(data $ ymax , 3 : 5 )
71
+
72
+ # multiple nudge values, including zero
73
+ p <- ggplot(df , aes(y = x , ymax = x , ymin = x )) +
74
+ layer(geom = Geom , stat = StatIdentity , position = position_nudge(y = c(0 , - 1 , - 2 )))
75
+
76
+ data <- layer_data(p )
77
+
78
+ expect_equal(data $ y , c(1 , 1 , 1 ))
79
+ expect_equal(data $ ymin , c(1 , 1 , 1 ))
80
+ expect_equal(data $ ymax , c(1 , 1 , 1 ))
81
+
43
82
})
0 commit comments