@@ -45,7 +45,8 @@ test_that("complex alignments, h, v, hv", {
45
45
expect_equal(plots [[1 ]]$ widths [1 : 4 ], plots [[2 ]]$ widths [1 : 4 ])
46
46
47
47
plots <- align_plots(p1 , p2 , align = " v" , axis = " r" , greedy = FALSE ) # align right
48
- expect_equal(plots [[1 ]]$ widths [6 : 9 ], plots [[2 ]]$ widths [14 : 17 ])
48
+ n <- vapply(plots , ncol , integer(1 ))
49
+ expect_equal(plots [[1 ]]$ widths [n [1 ] - 3 : 0 ], plots [[2 ]]$ widths [n [2 ] - 3 : 0 ])
49
50
50
51
# with greedy = TRUE, only the sums of the widths are equal
51
52
plots <- align_plots(p1 , p2 , align = " v" , axis = " l" , greedy = TRUE ) # align left
@@ -55,9 +56,10 @@ test_that("complex alignments, h, v, hv", {
55
56
)
56
57
57
58
plots <- align_plots(p1 , p2 , align = " v" , axis = " r" , greedy = TRUE ) # align right
59
+ n <- vapply(plots , ncol , integer(1 ))
58
60
expect_equal(
59
- grid :: convertUnit(sum(plots [[1 ]]$ widths [6 : 9 ]), " in" ),
60
- grid :: convertUnit(sum(plots [[2 ]]$ widths [14 : 17 ]), " in" )
61
+ grid :: convertUnit(sum(plots [[1 ]]$ widths [n [ 1 ] - 3 : 0 ]), " in" ),
62
+ grid :: convertUnit(sum(plots [[2 ]]$ widths [n [ 2 ] - 3 : 0 ]), " in" )
61
63
)
62
64
63
65
@@ -68,15 +70,17 @@ test_that("complex alignments, h, v, hv", {
68
70
expect_warning(align_plots(p1 , p3 , align = " h" ))
69
71
70
72
plots <- align_plots(p1 , p3 , align = " h" , axis = " bt" , greedy = FALSE )
73
+ n <- vapply(plots , nrow , integer(1 ))
71
74
expect_equal(
72
- grid :: convertUnit(plots [[1 ]]$ heights [7 : 10 ] - plots [[2 ]]$ heights [18 : 21 ], " cm" ),
75
+ grid :: convertUnit(plots [[1 ]]$ heights [n [ 1 ] - 3 : 0 ] - plots [[2 ]]$ heights [n [ 2 ] - 3 : 0 ], " cm" ),
73
76
grid :: unit(c(0 , 0 , 0 , 0 ), " cm" )
74
77
)
75
78
76
79
# these units are only equal after we've added everything up
80
+ rows <- c(panel_rows(plots [[1 ]])$ t [1 ], panel_rows(plots [[2 ]])$ t [1 ]) - 1
77
81
expect_equal(
78
- grid :: convertUnit(sum(plots [[1 ]]$ heights [1 : 6 ]), " cm" ),
79
- grid :: convertUnit(sum(plots [[2 ]]$ heights [1 : 7 ]), " cm" )
82
+ grid :: convertUnit(sum(plots [[1 ]]$ heights [1 : rows [ 1 ] ]), " cm" ),
83
+ grid :: convertUnit(sum(plots [[2 ]]$ heights [1 : rows [ 2 ] ]), " cm" )
80
84
)
81
85
dev.off()
82
86
})
@@ -106,14 +110,16 @@ test_that("complex alignments with non-plots", {
106
110
107
111
# because p1 has a legend and p2 doesn't, only the sums of the widths are equal for right align
108
112
plots <- align_plots(p1 , p2 , p3 , align = " v" , axis = " r" , greedy = FALSE ) # align right
113
+ n <- vapply(plots , ncol , integer(1 ))
109
114
expect_equal(
110
- grid :: convertUnit(sum(plots [[1 ]]$ widths [6 : 11 ]), " in" ),
111
- grid :: convertUnit(sum(plots [[2 ]]$ widths [14 : 17 ]), " in" )
115
+ grid :: convertUnit(sum(plots [[1 ]]$ widths [n [ 1 ] - 5 : 0 ]), " in" ),
116
+ grid :: convertUnit(sum(plots [[2 ]]$ widths [n [ 2 ] - 3 : 0 ]), " in" )
112
117
)
113
118
plots <- align_plots(p1 , NULL , p2 , p3 , align = " v" , axis = " r" , greedy = FALSE ) # align right
119
+ n <- vapply(plots , NCOL , integer(1 ))
114
120
expect_equal(
115
- grid :: convertUnit(sum(plots [[1 ]]$ widths [6 : 11 ]), " in" ),
116
- grid :: convertUnit(sum(plots [[3 ]]$ widths [14 : 17 ]), " in" )
121
+ grid :: convertUnit(sum(plots [[1 ]]$ widths [n [ 1 ] - 5 : 0 ]), " in" ),
122
+ grid :: convertUnit(sum(plots [[3 ]]$ widths [n [ 3 ] - 3 : 0 ]), " in" )
117
123
)
118
124
119
125
# with greedy = TRUE, only the sums of the widths are equal
@@ -129,14 +135,16 @@ test_that("complex alignments with non-plots", {
129
135
)
130
136
131
137
plots <- align_plots(p1 , p2 , p3 , align = " v" , axis = " r" , greedy = TRUE ) # align right
138
+ n <- vapply(plots , ncol , integer(1 ))
132
139
expect_equal(
133
- grid :: convertUnit(sum(plots [[1 ]]$ widths [6 : 11 ]), " in" ),
134
- grid :: convertUnit(sum(plots [[2 ]]$ widths [14 : 17 ]), " in" )
140
+ grid :: convertUnit(sum(plots [[1 ]]$ widths [n [ 1 ] - 5 : 0 ]), " in" ),
141
+ grid :: convertUnit(sum(plots [[2 ]]$ widths [n [ 2 ] - 3 : 0 ]), " in" )
135
142
)
136
143
plots <- align_plots(p1 , NULL , p2 , align = " v" , axis = " r" , greedy = TRUE ) # align right
144
+ n <- vapply(plots , NCOL , integer(1 ))
137
145
expect_equal(
138
- grid :: convertUnit(sum(plots [[1 ]]$ widths [6 : 11 ]), " in" ),
139
- grid :: convertUnit(sum(plots [[3 ]]$ widths [14 : 17 ]), " in" )
146
+ grid :: convertUnit(sum(plots [[1 ]]$ widths [n [ 1 ] - 5 : 0 ]), " in" ),
147
+ grid :: convertUnit(sum(plots [[3 ]]$ widths [n [ 3 ] - 3 : 0 ]), " in" )
140
148
)
141
149
142
150
dev.off()
0 commit comments