@@ -26,19 +26,30 @@ test_that("geom_sf() determines the legend type automatically", {
26
26
geometry = sf :: st_sfc(sf :: st_multipolygon(list (list (p1 ,p2 ), list (p3 ,p4 ), list (p5 )))),
27
27
v = " a" )
28
28
29
- fun_geom_sf <- function (sf ) {
30
- p <- ggplot() + geom_sf(aes(colour = v ), data = sf , show.legend = TRUE )
29
+ fun_geom_sf <- function (sf , show.legend ) {
30
+ p <- ggplot() + geom_sf(aes(colour = v ), data = sf , show.legend = show.legend )
31
31
ggplot_build(p )
32
32
}
33
33
34
- expect_identical(fun_geom_sf(mp )$ plot $ layers [[1 ]]$ show.legend , TRUE )
35
- expect_identical(fun_geom_sf(mp )$ plot $ layers [[1 ]]$ geom_params $ legend , " point" )
34
+ # test the automatic choice
35
+ expect_identical(fun_geom_sf(mp , TRUE )$ plot $ layers [[1 ]]$ show.legend , TRUE )
36
+ expect_identical(fun_geom_sf(mp , TRUE )$ plot $ layers [[1 ]]$ geom_params $ legend , " point" )
36
37
37
- expect_identical(fun_geom_sf(mls )$ plot $ layers [[1 ]]$ show.legend , TRUE )
38
- expect_identical(fun_geom_sf(mls )$ plot $ layers [[1 ]]$ geom_params $ legend , " line" )
38
+ expect_identical(fun_geom_sf(mls , TRUE )$ plot $ layers [[1 ]]$ show.legend , TRUE )
39
+ expect_identical(fun_geom_sf(mls , TRUE )$ plot $ layers [[1 ]]$ geom_params $ legend , " line" )
39
40
40
- expect_identical(fun_geom_sf(mpol )$ plot $ layers [[1 ]]$ show.legend , TRUE )
41
- expect_identical(fun_geom_sf(mpol )$ plot $ layers [[1 ]]$ geom_params $ legend , " polygon" )
41
+ expect_identical(fun_geom_sf(mpol , TRUE )$ plot $ layers [[1 ]]$ show.legend , TRUE )
42
+ expect_identical(fun_geom_sf(mpol , TRUE )$ plot $ layers [[1 ]]$ geom_params $ legend , " polygon" )
43
+
44
+ # test that automatic choice can be overridden manually
45
+ expect_identical(fun_geom_sf(mp , " point" )$ plot $ layers [[1 ]]$ show.legend , TRUE )
46
+ expect_identical(fun_geom_sf(mp , " point" )$ plot $ layers [[1 ]]$ geom_params $ legend , " point" )
47
+
48
+ expect_identical(fun_geom_sf(mls , " point" )$ plot $ layers [[1 ]]$ show.legend , TRUE )
49
+ expect_identical(fun_geom_sf(mls , " point" )$ plot $ layers [[1 ]]$ geom_params $ legend , " point" )
50
+
51
+ expect_identical(fun_geom_sf(mpol , " point" )$ plot $ layers [[1 ]]$ show.legend , TRUE )
52
+ expect_identical(fun_geom_sf(mpol , " point" )$ plot $ layers [[1 ]]$ geom_params $ legend , " point" )
42
53
})
43
54
44
55
test_that(" geom_sf() removes rows containing missing aes" , {
0 commit comments