11context(" position_nudgestack" )
22
33test_that(" position_nudgestack draws correctly" , {
4-
54 ESM <- tsbox :: ts_tbl(EuStockMarkets )
65
76 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" ))) %> %
98 dplyr :: group_by(id , time ) %> %
109 dplyr :: summarize(value = mean(value )) %> %
1110 dplyr :: filter(time > = " 1995-01-01" & time < " 1998-01-01" )
1211
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+ ) +
1416 geom_col(position = position_nudgestack(x = 15 ))
1517
1618 expect_doppelganger(
@@ -35,18 +37,17 @@ test_that("nudging works in both dimensions simultaneously", {
3537 expect_equal(data $ xmin , 1.05 : 3.05 )
3638 expect_equal(data $ xmax , 1.95 : 3.95 )
3739 expect_equal(data $ y , 3 : 5 )
38- expect_equal(data $ ymin , c(2 ,2 , 2 ))
40+ expect_equal(data $ ymin , c(2 , 2 , 2 ))
3941 expect_equal(data $ ymax , 3 : 5 )
40-
4142})
4243
4344test_that(" nudging works for discrete values correctly" , {
4445 set.seed(111 )
4546
4647 # x nudge value for discrete data
4748 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 ),
5051 value = rpois(16 , 10 )
5152 )
5253
@@ -56,10 +57,9 @@ test_that("nudging works for discrete values correctly", {
5657
5758 data <- layer_data(p )
5859
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 )))
6363})
6464
6565
@@ -78,9 +78,9 @@ test_that("data is sorted prior to stacking", {
7878
7979test_that(" negative and positive values are handled separately" , {
8080 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 )
8484 )
8585 p <- ggplot(df , aes(x , y , fill = factor (g ))) +
8686 geom_col(position = position_nudgestack(x = 0.5 ))
@@ -110,4 +110,3 @@ test_that("position_nudgestack() can stack correctly when ymax is NA", {
110110 geom_point(position = position_nudgestack(x = 0.5 ))
111111 expect_equal(layer_data(p )$ y , c(1 , 2 ))
112112})
113-
0 commit comments