|
1 | 1 | context("geom-sf")
|
2 | 2 |
|
| 3 | +test_that("geom_sf() determines the legend type automatically", { |
| 4 | + skip_if_not_installed("sf") |
| 5 | + if (packageVersion("sf") < "0.5.3") skip("Need sf 0.5.3") |
| 6 | + |
| 7 | + mp <- sf::st_sf( |
| 8 | + geometry = sf::st_sfc(sf::st_multipoint(rbind(c(1,1), c(2,2), c(3,3)))), |
| 9 | + v = "a") |
| 10 | + |
| 11 | + s1 <- rbind(c(0,3),c(0,4),c(1,5),c(2,5)) |
| 12 | + s2 <- rbind(c(0.2,3), c(0.2,4), c(1,4.8), c(2,4.8)) |
| 13 | + s3 <- rbind(c(0,4.4), c(0.6,5)) |
| 14 | + |
| 15 | + mls <- sf::st_sf( |
| 16 | + geometry = sf::st_sfc(sf::st_multilinestring(list(s1,s2,s3))), |
| 17 | + v = "a") |
| 18 | + |
| 19 | + p1 <- rbind(c(0,0), c(1,0), c(3,2), c(2,4), c(1,4), c(0,0)) |
| 20 | + p2 <- rbind(c(1,1), c(1,2), c(2,2), c(1,1)) |
| 21 | + p3 <- rbind(c(3,0), c(4,0), c(4,1), c(3,1), c(3,0)) |
| 22 | + p4 <- rbind(c(3.3,0.3), c(3.8,0.3), c(3.8,0.8), c(3.3,0.8), c(3.3,0.3))[5:1,] |
| 23 | + p5 <- rbind(c(3,3), c(4,2), c(4,3), c(3,3)) |
| 24 | + |
| 25 | + mpol <- sf::st_sf( |
| 26 | + geometry = sf::st_sfc(sf::st_multipolygon(list(list(p1,p2), list(p3,p4), list(p5)))), |
| 27 | + v = "a") |
| 28 | + |
| 29 | + fun_geom_sf <- function(sf) { |
| 30 | + p <- ggplot() + geom_sf(aes(colour = v), data = sf, show.legend = TRUE) |
| 31 | + ggplot_build(p) |
| 32 | + } |
| 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") |
| 36 | + |
| 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") |
| 39 | + |
| 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") |
| 42 | +}) |
| 43 | + |
3 | 44 | test_that("geom_sf() removes rows containing missing aes", {
|
4 | 45 | skip_if_not_installed("sf")
|
5 | 46 | if (packageVersion("sf") < "0.5.3") skip("Need sf 0.5.3")
|
|
0 commit comments