11context(" position_nudge" )
22
33test_that(" nudging works in both dimensions simultaneously" , {
4+ # individual nudge value
45 df <- data_frame(x = 1 : 3 )
56
67 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", {
1415 expect_equal(data $ y , 3 : 5 )
1516 expect_equal(data $ ymin , 3 : 5 )
1617 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+
1734})
1835
1936test_that(" nudging works in individual dimensions" , {
@@ -30,6 +47,17 @@ test_that("nudging works in individual dimensions", {
3047 expect_equal(data $ xmin , 2 : 4 )
3148 expect_equal(data $ xmax , 2 : 4 )
3249
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+
3361 # nudging in y
3462 # use an empty layer so can test individual aesthetics
3563 p <- ggplot(df , aes(y = x , ymax = x , ymin = x )) +
@@ -40,4 +68,15 @@ test_that("nudging works in individual dimensions", {
4068 expect_equal(data $ y , 3 : 5 )
4169 expect_equal(data $ ymin , 3 : 5 )
4270 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+
4382})
0 commit comments