@@ -4,9 +4,10 @@ PlantGrowth$type <-
4
4
ifelse(PlantGrowth $ group == " ctrl" , " control" , " treatment" )
5
5
boxes <- ggplot(PlantGrowth , aes(x = group , y = weight )) + geom_boxplot()
6
6
7
- expect_traces <- function (gg , n.traces ){
7
+ expect_traces <- function (gg , n.traces , name ){
8
8
stopifnot(is.ggplot(gg ))
9
9
stopifnot(is.numeric(n.traces ))
10
+ save_outputs(gg , paste0(" ticks-" , name ))
10
11
L <- gg2list(gg )
11
12
is.trace <- names(L ) == " "
12
13
all.traces <- L [is.trace ]
@@ -22,7 +23,7 @@ plant.list <- split(PlantGrowth, PlantGrowth$group)
22
23
weight.range <- range(PlantGrowth $ weight )
23
24
24
25
test_that(" boxes without coord_flip()" , {
25
- info <- expect_traces(boxes , 3 )
26
+ info <- expect_traces(boxes , 3 , " boxes " )
26
27
for (tr in info $ traces ){
27
28
expect_true(is.null(tr [[" x" ]]))
28
29
expected <- plant.list [[tr $ name ]]$ weight
@@ -33,7 +34,7 @@ test_that("boxes without coord_flip()", {
33
34
34
35
test_that(" boxes with facet_grid" , {
35
36
facets <- boxes + facet_grid(. ~ type )
36
- info <- expect_traces(facets , 3 )
37
+ info <- expect_traces(facets , 3 , " boxes-facet-grid " )
37
38
# # TODO: expect boxes of equal size.
38
39
39
40
# # TODO: expect empty space.
@@ -47,7 +48,7 @@ test_that("boxes with facet_grid", {
47
48
48
49
test_that(' boxes with facet_grid(scales="free")' , {
49
50
facets.scales <- boxes + facet_grid(. ~ type , scales = " free" )
50
- info <- expect_traces(facets.scales , 3 )
51
+ info <- expect_traces(facets.scales , 3 , " boxes-scales-free " )
51
52
# # TODO: expect boxes of unequal size.
52
53
53
54
# # TODO: expect no empty space.
@@ -61,7 +62,7 @@ test_that('boxes with facet_grid(scales="free")', {
61
62
62
63
test_that(' boxes with facet_grid(scales="free", space="free")' , {
63
64
facets.space <- boxes + facet_grid(. ~ type , scales = " free" , space = " free" )
64
- info <- expect_traces(facets.space , 3 )
65
+ info <- expect_traces(facets.space , 3 , " boxes-space-free " )
65
66
# # TODO: expect boxes of equal size.
66
67
67
68
# # TODO: expect no empty space.
@@ -76,7 +77,7 @@ test_that('boxes with facet_grid(scales="free", space="free")', {
76
77
flipped <- boxes + coord_flip()
77
78
78
79
test_that(" boxes with coord_flip()" , {
79
- info <- expect_traces(flipped , 3 )
80
+ info <- expect_traces(flipped , 3 , " flip " )
80
81
for (tr in info $ traces ){
81
82
expect_true(is.null(tr [[" y" ]]))
82
83
expected <- plant.list [[tr $ name ]]$ weight
@@ -126,23 +127,23 @@ test_that('boxes+facet_grid(scales="free", space="free")+coord_flip()', {
126
127
test_that(" Manually set the order of a discrete-valued axis" , {
127
128
expected.order <- c(" trt1" , " ctrl" , " trt2" )
128
129
boxes.limits <- boxes + scale_x_discrete(limits = expected.order )
129
- info <- expect_traces(boxes.limits , 3 )
130
+ info <- expect_traces(boxes.limits , 3 , " discrete-order " )
130
131
computed.order <- sapply(info $ traces , " [[" , " name" )
131
132
expect_identical(as.character(computed.order ), expected.order )
132
133
})
133
134
134
135
test_that(" limits can hide data" , {
135
136
expected.order <- c(" trt1" , " ctrl" )
136
137
boxes.limits <- boxes + scale_x_discrete(limits = expected.order )
137
- info <- expect_traces(boxes.limits , 2 )
138
+ info <- expect_traces(boxes.limits , 2 , " limits-hide " )
138
139
computed.order <- sapply(info $ traces , " [[" , " name" )
139
140
expect_identical(as.character(computed.order ), expected.order )
140
141
})
141
142
142
143
test_that(" limits can create a gap" , {
143
144
expected.order <- c(" trt1" , " trt2" , " GAP" , " ctrl" )
144
145
boxes.limits <- boxes + scale_x_discrete(limits = expected.order )
145
- info <- expect_traces(boxes.limits , 3 )
146
+ info <- expect_traces(boxes.limits , 3 , " limits-gap " )
146
147
computed.order <- sapply(info $ traces , " [[" , " name" )
147
148
# #expect_identical(as.character(computed.order), expected.order)
148
149
@@ -153,7 +154,7 @@ boxes.breaks <- boxes +
153
154
scale_x_discrete(breaks = c(" trt1" , " ctrl" , " trt2" ))
154
155
155
156
test_that(" setting breaks does not change order" , {
156
- info <- expect_traces(boxes.breaks , 3 )
157
+ info <- expect_traces(boxes.breaks , 3 , " breaks-nochange " )
157
158
computed.labels <- sapply(info $ traces , " [[" , " name" )
158
159
expect_identical(as.character(computed.labels ), c(" ctrl" , " trt1" , " trt2" ))
159
160
})
@@ -162,7 +163,7 @@ boxes.more <- boxes +
162
163
scale_x_discrete(breaks = c(" trt1" , " ctrl" , " trt2" , " FOO" ))
163
164
164
165
test_that(" more breaks is fine" , {
165
- info <- expect_traces(boxes.more , 3 )
166
+ info <- expect_traces(boxes.more , 3 , " breaks-more " )
166
167
computed.labels <- sapply(info $ traces , " [[" , " name" )
167
168
expect_identical(as.character(computed.labels ), c(" ctrl" , " trt1" , " trt2" ))
168
169
})
@@ -171,7 +172,7 @@ boxes.less <- boxes +
171
172
scale_x_discrete(breaks = c(" trt1" , " ctrl" ))
172
173
173
174
test_that(" less breaks is fine" , {
174
- info <- expect_traces(boxes.less , 3 )
175
+ info <- expect_traces(boxes.less , 3 , " breaks-less " )
175
176
computed.labels <- sapply(info $ traces , " [[" , " name" )
176
177
# #expect_identical(as.character(computed.labels), c("ctrl", "trt1", "trt2"))
177
178
@@ -183,7 +184,7 @@ boxes.labels <- boxes +
183
184
labels = c(" Treatment 1" , " Control" , " Treatment 2" ))
184
185
185
186
test_that(" scale(labels) changes trace names" , {
186
- info <- expect_traces(boxes.labels , 3 )
187
+ info <- expect_traces(boxes.labels , 3 , " scale-labels " )
187
188
computed.labels <- sapply(info $ traces , " [[" , " name" )
188
189
expect_identical(as.character(computed.labels ),
189
190
c(" Control" , " Treatment 1" , " Treatment 2" ))
@@ -192,7 +193,7 @@ test_that("scale(labels) changes trace names", {
192
193
no.breaks <- boxes + scale_x_discrete(breaks = NULL )
193
194
194
195
test_that(" hide x ticks, lines, and labels" , {
195
- info <- expect_traces(no.breaks , 3 )
196
+ info <- expect_traces(no.breaks , 3 , " hide-ticks-lines-labels " )
196
197
x <- info $ kwargs $ layout $ xaxis
197
198
expect_identical(x [[" showticklabels" ]], FALSE )
198
199
# #expect_identical(x[["showline"]], FALSE) #irrelevant.
@@ -213,7 +214,7 @@ test_that("hide x ticks, lines, and labels", {
213
214
test_that(" Hide X ticks and labels, but keep the gridlines" , {
214
215
boxes.grid <- boxes +
215
216
theme(axis.ticks = element_blank(), axis.text.x = element_blank())
216
- info <- expect_traces(boxes.grid , 3 )
217
+ info <- expect_traces(boxes.grid , 3 , " hide-ticks-labels " )
217
218
x <- info $ kwargs $ layout $ xaxis
218
219
expect_identical(x [[" showticklabels" ]], FALSE )
219
220
expect_identical(x [[" showgrid" ]], TRUE )
@@ -222,14 +223,14 @@ test_that("Hide X ticks and labels, but keep the gridlines", {
222
223
223
224
test_that(" scale_y_continuous(limits) means yaxis$ranges" , {
224
225
boxes.range <- boxes + scale_y_continuous(limits = c(0 ,8 ))
225
- info <- expect_traces(boxes.range , 3 )
226
+ info <- expect_traces(boxes.range , 3 , " ycontinuous-ranges " )
226
227
y.axis <- info $ kwargs $ layout $ yaxis
227
228
expect_equal(y.axis $ range , c(0 , 8 ))
228
229
})
229
230
230
231
test_that(" ylim() means yaxis$ranges" , {
231
232
boxes.range <- boxes + ylim(0 ,8 )
232
- info <- expect_traces(boxes.range , 3 )
233
+ info <- expect_traces(boxes.range , 3 , " ylim-ranges " )
233
234
y.axis <- info $ kwargs $ layout $ yaxis
234
235
expect_equal(y.axis $ range , c(0 , 8 ))
235
236
# # ensure correct positive values without reverse scale.
@@ -243,7 +244,7 @@ test_that("ylim() means yaxis$ranges", {
243
244
244
245
test_that(" scale_y_reverse() -> yaxis$ranges reversed" , {
245
246
boxes.reverse <- boxes + scale_y_reverse()
246
- info <- expect_traces(boxes.reverse , 3 )
247
+ info <- expect_traces(boxes.reverse , 3 , " yreverse-ranges " )
247
248
y.axis <- info $ kwargs $ layout $ yaxis
248
249
expect_that(y.axis $ range [2 ], is_less_than(y.axis $ range [1 ]))
249
250
# # ensure correct positive values, despite the reverse scale.
@@ -258,7 +259,7 @@ test_that("scale_y_reverse() -> yaxis$ranges reversed", {
258
259
test_that(" scale_y_reverse(limits) -> yaxis$ranges reversed" , {
259
260
y.lim <- c(10 , - 2 )
260
261
boxes.reverse <- boxes + scale_y_reverse(limits = y.lim )
261
- info <- expect_traces(boxes.reverse , 3 )
262
+ info <- expect_traces(boxes.reverse , 3 , " yreverse-limits-ranges " )
262
263
y.axis <- info $ kwargs $ layout $ yaxis
263
264
expect_equal(y.axis $ range , y.lim )
264
265
# # ensure correct positive values, despite the reverse scale.
@@ -272,7 +273,7 @@ test_that("scale_y_reverse(limits) -> yaxis$ranges reversed", {
272
273
273
274
test_that(" ylim(reversed) -> yaxis$ranges reversed" , {
274
275
boxes.reverse <- boxes + ylim(7.5 , - 1 )
275
- info <- expect_traces(boxes.reverse , 3 )
276
+ info <- expect_traces(boxes.reverse , 3 , " ylim-reversed-ranges " )
276
277
y.axis <- info $ kwargs $ layout $ yaxis
277
278
expect_equal(y.axis $ range , c(7.5 , - 1 ))
278
279
# # ensure correct positive values, despite the reverse scale.
@@ -288,7 +289,7 @@ test_that("Set the X tick mark locations", {
288
289
# # This will show tick marks on every 0.25 from 1 to 10. The scale will
289
290
# # show only the ones that are within range (3.50-6.25 in this case)
290
291
boxes.ticks <- boxes + scale_y_continuous(breaks = seq(1 ,10 ,1 / 4 ))
291
- info <- expect_traces(boxes.ticks , 3 )
292
+ info <- expect_traces(boxes.ticks , 3 , " evenly-spaced-ticks " )
292
293
y.axis <- info $ kwargs $ layout $ yaxis
293
294
expect_equal(y.axis $ dtick , 0.25 )
294
295
expect_identical(y.axis $ autotick , FALSE )
@@ -303,7 +304,7 @@ test_that("The breaks can be spaced unevenly", {
303
304
304
305
test_that(" hide y ticks, lines, and labels" , {
305
306
no.breaks <- boxes + scale_y_continuous(breaks = NULL )
306
- info <- expect_traces(no.breaks , 3 )
307
+ info <- expect_traces(no.breaks , 3 , " hide-y " )
307
308
y.axis <- info $ kwargs $ layout $ yaxis
308
309
expect_identical(y.axis [[" showgrid" ]], FALSE )
309
310
expect_identical(y.axis [[" ticks" ]], " " )
@@ -313,7 +314,7 @@ test_that("hide y ticks, lines, and labels", {
313
314
test_that(" hide y ticks and labels, but keep the gridlines" , {
314
315
boxes.ygrid <- boxes +
315
316
theme(axis.ticks = element_blank(), axis.text.y = element_blank())
316
- info <- expect_traces(boxes.ygrid , 3 )
317
+ info <- expect_traces(boxes.ygrid , 3 , " hide-y-keep-grid " )
317
318
y.axis <- info $ kwargs $ layout $ yaxis
318
319
expect_identical(y.axis [[" showgrid" ]], TRUE )
319
320
expect_identical(y.axis [[" ticks" ]], " " )
0 commit comments