@@ -74,12 +74,13 @@ test_that("wrap_as_facets_list() and grid_as_facets_list() accept empty specs",
74
74
expect_identical(grid_as_facets_list(list (NULL ), NULL ), list (rows = quos(), cols = quos()))
75
75
})
76
76
77
- df <- data_frame(x = 1 : 3 , y = 3 : 1 , z = letters [1 : 3 ])
78
-
79
77
test_that(" facets split up the data" , {
80
- l1 <- ggplot(df , aes(x , y )) + geom_point() + facet_wrap(~ z )
81
- l2 <- ggplot(df , aes(x , y )) + geom_point() + facet_grid(. ~ z )
82
- l3 <- ggplot(df , aes(x , y )) + geom_point() + facet_grid(z ~ . )
78
+ df <- data_frame(x = 1 : 3 , y = 3 : 1 , z = letters [1 : 3 ])
79
+ p <- ggplot(df , aes(x , y )) + geom_point()
80
+
81
+ l1 <- p + facet_wrap(~ z )
82
+ l2 <- p + facet_grid(. ~ z )
83
+ l3 <- p + facet_grid(z ~ . )
83
84
84
85
d1 <- layer_data(l1 )
85
86
d2 <- layer_data(l2 )
@@ -88,11 +89,23 @@ test_that("facets split up the data", {
88
89
expect_equal(d1 , d2 )
89
90
expect_equal(d1 , d3 )
90
91
expect_equal(d1 $ PANEL , factor (1 : 3 ))
92
+
93
+ # Handle empty layers
94
+ p_empty <- ggplot() + geom_point(aes(x , y ), df ) + geom_line()
95
+ l4 <- p_empty + facet_wrap(~ z )
96
+ l5 <- p_empty + facet_grid(. ~ z )
97
+
98
+ d4 <- layer_data(l4 )
99
+ d5 <- layer_data(l5 )
100
+
101
+ expect_equal(d1 , d4 )
102
+ expect_equal(d1 , d5 )
91
103
})
92
104
105
+
93
106
test_that(" facet_wrap() accepts vars()" , {
107
+ df <- data_frame(x = 1 : 3 , y = 3 : 1 , z = letters [1 : 3 ])
94
108
p <- ggplot(df , aes(x , y )) + geom_point()
95
- p2 <- p + facet_wrap(vars(z ))
96
109
97
110
p1 <- p + facet_wrap(~ z )
98
111
p2 <- p + facet_wrap(vars(Z = z ), labeller = label_both )
@@ -136,44 +149,52 @@ test_that("vars() accepts optional names", {
136
149
expect_named(wrap $ params $ facets , c(" A" , " b" ))
137
150
})
138
151
139
- test_that(" facets_wrap() compacts the facet spec and accept empty spec" , {
140
- p <- ggplot( df , aes( x , y )) + geom_point() + facet_wrap(vars( NULL ) )
141
- d <- layer_data( p )
152
+ test_that(" facet_wrap()/facet_grid() compact the facet spec, and accept empty spec" , {
153
+ df <- data_frame( x = 1 : 3 , y = 3 : 1 , z = letters [ 1 : 3 ] )
154
+ p <- ggplot( df , aes( x , y )) + geom_point( )
142
155
143
- expect_equal(d $ PANEL , factor (c(1L , 1L , 1L )))
144
- expect_equal(d $ group , structure(c(- 1L , - 1L , - 1L ), n = 1L ))
145
- })
156
+ # facet_wrap()
157
+ p_wrap <- p + facet_wrap(vars(NULL ))
158
+ d_wrap <- layer_data(p_wrap )
159
+
160
+ expect_equal(d_wrap $ PANEL , factor (c(1L , 1L , 1L )))
161
+ expect_equal(d_wrap $ group , structure(c(- 1L , - 1L , - 1L ), n = 1L ))
146
162
147
- test_that( " facets_grid() compacts the facet spec and accept empty spec " , {
148
- p <- ggplot( df , aes( x , y )) + geom_point() + facet_grid(vars(NULL ))
149
- d <- layer_data(p )
163
+ # facet_grid()
164
+ p_grid <- p + facet_grid(vars(NULL ))
165
+ d_grid <- layer_data(p_grid )
150
166
151
- expect_equal(d $ PANEL , factor (c(1L , 1L , 1L )))
152
- expect_equal(d $ group , structure(c(- 1L , - 1L , - 1L ), n = 1L ))
167
+ expect_equal(d_grid $ PANEL , factor (c(1L , 1L , 1L )))
168
+ expect_equal(d_grid $ group , structure(c(- 1L , - 1L , - 1L ), n = 1L ))
153
169
})
154
170
155
171
156
172
test_that(" facets with free scales scale independently" , {
157
- l1 <- ggplot(df , aes(x , y )) + geom_point() +
158
- facet_wrap(~ z , scales = " free" )
173
+ df <- data_frame(x = 1 : 3 , y = 3 : 1 , z = letters [1 : 3 ])
174
+ p <- ggplot(df , aes(x , y )) + geom_point()
175
+
176
+ # facet_wrap()
177
+ l1 <- p + facet_wrap(~ z , scales = " free" )
159
178
d1 <- cdata(l1 )[[1 ]]
160
179
expect_true(sd(d1 $ x ) < 1e-10 )
161
180
expect_true(sd(d1 $ y ) < 1e-10 )
162
181
163
- l2 <- ggplot( df , aes( x , y )) + geom_point() +
164
- facet_grid(. ~ z , scales = " free" )
182
+ # RHS of facet_grid()
183
+ l2 <- p + facet_grid(. ~ z , scales = " free" )
165
184
d2 <- cdata(l2 )[[1 ]]
166
185
expect_true(sd(d2 $ x ) < 1e-10 )
167
186
expect_equal(length(unique(d2 $ y )), 3 )
168
187
169
- l3 <- ggplot( df , aes( x , y )) + geom_point() +
170
- facet_grid(z ~ . , scales = " free" )
188
+ # LHS of facet_grid()
189
+ l3 <- p + facet_grid(z ~ . , scales = " free" )
171
190
d3 <- cdata(l3 )[[1 ]]
172
191
expect_equal(length(unique(d3 $ x )), 3 )
173
192
expect_true(sd(d3 $ y ) < 1e-10 )
174
193
})
175
194
176
195
test_that(" shrink parameter affects scaling" , {
196
+ df <- data_frame(x = 1 : 3 , y = 3 : 1 , z = letters [1 : 3 ])
197
+
177
198
l1 <- ggplot(df , aes(1 , y )) + geom_point()
178
199
r1 <- pranges(l1 )
179
200
0 commit comments