1
1
context(" position_nudgestack" )
2
2
3
3
test_that(" position_nudgestack draws correctly" , {
4
-
5
4
ESM <- tsbox :: ts_tbl(EuStockMarkets )
6
5
7
6
ESM_prep <- ESM %> %
8
- dplyr :: mutate(time = as.Date(paste0(format(time , " %Y-%m" )," -1" ))) %> %
7
+ dplyr :: mutate(time = as.Date(paste0(format(time , " %Y-%m" ), " -1" ))) %> %
9
8
dplyr :: group_by(id , time ) %> %
10
9
dplyr :: summarize(value = mean(value )) %> %
11
10
dplyr :: filter(time > = " 1995-01-01" & time < " 1998-01-01" )
12
11
13
- stock_marked <- ggplot(data = ESM_prep , mapping = aes(x = time , y = value , fill = id )) +
12
+ stock_marked <- ggplot(
13
+ data = ESM_prep ,
14
+ mapping = aes(x = time , y = value , fill = id )
15
+ ) +
14
16
geom_col(position = position_nudgestack(x = 15 ))
15
17
16
18
expect_doppelganger(
@@ -35,18 +37,17 @@ test_that("nudging works in both dimensions simultaneously", {
35
37
expect_equal(data $ xmin , 1.05 : 3.05 )
36
38
expect_equal(data $ xmax , 1.95 : 3.95 )
37
39
expect_equal(data $ y , 3 : 5 )
38
- expect_equal(data $ ymin , c(2 ,2 , 2 ))
40
+ expect_equal(data $ ymin , c(2 , 2 , 2 ))
39
41
expect_equal(data $ ymax , 3 : 5 )
40
-
41
42
})
42
43
43
44
test_that(" nudging works for discrete values correctly" , {
44
45
set.seed(111 )
45
46
46
47
# x nudge value for discrete data
47
48
series <- data_frame(
48
- time = factor (c(rep(1 , 4 ),rep(2 , 4 ), rep(3 , 4 ), rep(4 , 4 ))),
49
- type = rep(c(' a ' , ' b ' , ' c ' , ' d ' ), 4 ),
49
+ time = factor (c(rep(1 , 4 ), rep(2 , 4 ), rep(3 , 4 ), rep(4 , 4 ))),
50
+ type = rep(c(" a " , " b " , " c " , " d " ), 4 ),
50
51
value = rpois(16 , 10 )
51
52
)
52
53
@@ -56,10 +57,9 @@ test_that("nudging works for discrete values correctly", {
56
57
57
58
data <- layer_data(p )
58
59
59
- expect_equal(data $ x , c(rep(1.5 , 4 ),rep(2.5 , 4 ), rep(3.5 , 4 ), rep(4.5 , 4 )))
60
- expect_equal(data $ xmin , c(rep(1.5 , 4 ),rep(2.5 , 4 ), rep(3.5 , 4 ), rep(4.5 , 4 )))
61
- expect_equal(data $ xmax , c(rep(1.5 , 4 ),rep(2.5 , 4 ), rep(3.5 , 4 ), rep(4.5 , 4 )))
62
-
60
+ expect_equal(data $ x , c(rep(1.5 , 4 ), rep(2.5 , 4 ), rep(3.5 , 4 ), rep(4.5 , 4 )))
61
+ expect_equal(data $ xmin , c(rep(1.5 , 4 ), rep(2.5 , 4 ), rep(3.5 , 4 ), rep(4.5 , 4 )))
62
+ expect_equal(data $ xmax , c(rep(1.5 , 4 ), rep(2.5 , 4 ), rep(3.5 , 4 ), rep(4.5 , 4 )))
63
63
})
64
64
65
65
@@ -78,9 +78,9 @@ test_that("data is sorted prior to stacking", {
78
78
79
79
test_that(" negative and positive values are handled separately" , {
80
80
df <- data_frame(
81
- x = c(1 ,1 , 1 , 2 , 2 ),
82
- g = c(1 ,2 , 3 , 1 , 2 ),
83
- y = c(1 ,- 1 ,1 , 2 , - 3 )
81
+ x = c(1 , 1 , 1 , 2 , 2 ),
82
+ g = c(1 , 2 , 3 , 1 , 2 ),
83
+ y = c(1 , - 1 , 1 , 2 , - 3 )
84
84
)
85
85
p <- ggplot(df , aes(x , y , fill = factor (g ))) +
86
86
geom_col(position = position_nudgestack(x = 0.5 ))
@@ -110,4 +110,3 @@ test_that("position_nudgestack() can stack correctly when ymax is NA", {
110
110
geom_point(position = position_nudgestack(x = 0.5 ))
111
111
expect_equal(layer_data(p )$ y , c(1 , 2 ))
112
112
})
113
-
0 commit comments