@@ -209,7 +209,7 @@ test_that("Size and alpha scales throw appropriate warnings for factors", {
209209 )
210210 # There should be no warnings for ordered factors
211211 expect_warning(ggplot_build(p + geom_point(aes(size = o ))), NA )
212- expect_warning(ggplot_build(p + geom_point(aes(alpha = o ))), NA )
212+ expect_warning(ggplot_build(p + geom_point(aes(alpha = o ))), NA )
213213})
214214
215215test_that(" Shape scale throws appropriate warnings for factors" , {
@@ -230,3 +230,44 @@ test_that("Shape scale throws appropriate warnings for factors", {
230230 " Using shapes for an ordinal variable is not advised"
231231 )
232232})
233+
234+ test_that(" Aesthetics can be set independently of scale name" , {
235+ df <- data.frame (
236+ x = LETTERS [1 : 3 ],
237+ y = LETTERS [4 : 6 ]
238+ )
239+ p <- ggplot(df , aes(x , y , fill = y )) +
240+ scale_colour_manual(values = c(" red" , " green" , " blue" ), aesthetics = " fill" )
241+
242+ expect_equal(layer_data(p )$ fill , c(" red" , " green" , " blue" ))
243+ })
244+
245+ test_that(" Multiple aesthetics can be set with one function call" , {
246+ df <- data.frame (
247+ x = LETTERS [1 : 3 ],
248+ y = LETTERS [4 : 6 ]
249+ )
250+ p <- ggplot(df , aes(x , y , colour = x , fill = y )) +
251+ scale_colour_manual(
252+ values = c(" grey20" , " grey40" , " grey60" , " red" , " green" , " blue" ),
253+ aesthetics = c(" colour" , " fill" )
254+ )
255+
256+ expect_equal(layer_data(p )$ colour , c(" grey20" , " grey40" , " grey60" ))
257+ expect_equal(layer_data(p )$ fill , c(" red" , " green" , " blue" ))
258+
259+ # color order is determined by data order, and breaks are combined where possible
260+ df <- data.frame (
261+ x = LETTERS [1 : 3 ],
262+ y = LETTERS [2 : 4 ]
263+ )
264+ p <- ggplot(df , aes(x , y , colour = x , fill = y )) +
265+ scale_colour_manual(
266+ values = c(" cyan" , " red" , " green" , " blue" ),
267+ aesthetics = c(" fill" , " colour" )
268+ )
269+
270+ expect_equal(layer_data(p )$ colour , c(" cyan" , " red" , " green" ))
271+ expect_equal(layer_data(p )$ fill , c(" red" , " green" , " blue" ))
272+ })
273+
0 commit comments