diff --git a/R/guides-axis.r b/R/guides-axis.r index ba2b98f507..62c6f29b1c 100644 --- a/R/guides-axis.r +++ b/R/guides-axis.r @@ -71,6 +71,15 @@ draw_axis <- function(break_positions, break_labels, axis_position, theme) { ) } + # break_labels can be a list() of language objects + if (is.list(break_labels)) { + if (any(vapply(break_labels, is.language, logical(1)))) { + break_labels <- do.call(expression, break_labels) + } else { + break_labels <- unlist(break_labels) + } + } + labels_grob <- exec( element_grob, label_element, !!position_dim := unit(break_positions, "native"), diff --git a/tests/figs/coord-sf/sf-polygons.svg b/tests/figs/coord-sf/sf-polygons.svg index 6d80f68be6..a3b1b6928c 100644 --- a/tests/figs/coord-sf/sf-polygons.svg +++ b/tests/figs/coord-sf/sf-polygons.svg @@ -13,182 +13,80 @@ - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + -34 -° -N -34.5 -° -N -35 -° -N -35.5 -° -N -36 -° -N -36.5 -° -N - - - - - - - - - - - -84 -° -W -82 -° -W -80 -° -W -78 -° -W -76 -° -W -sf-polygons +36.25 +° +N +36.3 +° +N +36.35 +° +N +36.4 +° +N +36.45 +° +N +36.5 +° +N +36.55 +° +N +36.6 +° +N + + + + + + + + + + + + + +81.7 +° +W +81.6 +° +W +81.5 +° +W +81.4 +° +W +81.3 +° +W +sf-polygons diff --git a/tests/figs/geom-sf/labels-for-north-carolina.svg b/tests/figs/geom-sf/labels-for-north-carolina.svg index c1643d8b1a..d5d41244c5 100644 --- a/tests/figs/geom-sf/labels-for-north-carolina.svg +++ b/tests/figs/geom-sf/labels-for-north-carolina.svg @@ -14,46 +14,32 @@ - - + + - - -Ashe - -Alleghany - -Surry - + + +ashe + -4354000 -4356000 -4358000 -4360000 -4362000 -4364000 -4366000 - - - - - - - - - - - --9075000 --9050000 --9025000 --9000000 -x -y -Labels for North Carolina +4357807 +4357807 +4357807 + + + + + + +-9072027 +-9072027 +-9072027 +x +y +Labels for North Carolina diff --git a/tests/figs/geom-sf/north-carolina-county-boundaries.svg b/tests/figs/geom-sf/north-carolina-county-boundaries.svg index 5dab3a70da..805823d951 100644 --- a/tests/figs/geom-sf/north-carolina-county-boundaries.svg +++ b/tests/figs/geom-sf/north-carolina-county-boundaries.svg @@ -13,182 +13,80 @@ - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + -34 -° -N -34.5 -° -N -35 -° -N -35.5 -° -N -36 -° -N -36.5 -° -N - - - - - - - - - - - -84 -° -W -82 -° -W -80 -° -W -78 -° -W -76 -° -W -North Carolina county boundaries +36.25 +° +N +36.3 +° +N +36.35 +° +N +36.4 +° +N +36.45 +° +N +36.5 +° +N +36.55 +° +N +36.6 +° +N + + + + + + + + + + + + + +81.7 +° +W +81.6 +° +W +81.5 +° +W +81.4 +° +W +81.3 +° +W +North Carolina county boundaries diff --git a/tests/figs/geom-sf/spatial-points.svg b/tests/figs/geom-sf/spatial-points.svg index 96a287563e..a12e85703f 100644 --- a/tests/figs/geom-sf/spatial-points.svg +++ b/tests/figs/geom-sf/spatial-points.svg @@ -13,65 +13,53 @@ - - + + - + - - + + - - - - - - - - - - - - - - - - + + + + -1.0 -1.2 -1.4 -1.6 -1.8 -2.0 - - - - - - - - - - - - - 0.0 - 0.2 - 0.4 - 0.6 - 0.8 - 1.0 -spatial points +1.0 +1.2 +1.4 +1.6 +1.8 +2.0 + + + + + + + + + + + + + 0.0 + 0.2 + 0.4 + 0.6 + 0.8 + 1.0 +spatial points diff --git a/tests/figs/geom-sf/texts-for-north-carolina.svg b/tests/figs/geom-sf/texts-for-north-carolina.svg index 633254ec86..3ab383d80a 100644 --- a/tests/figs/geom-sf/texts-for-north-carolina.svg +++ b/tests/figs/geom-sf/texts-for-north-carolina.svg @@ -14,43 +14,31 @@ - - + + - -Ashe -Alleghany -Surry - + +ashe + -4354000 -4356000 -4358000 -4360000 -4362000 -4364000 -4366000 - - - - - - - - - - - --9075000 --9050000 --9025000 --9000000 -x -y -Texts for North Carolina +4357807 +4357807 +4357807 + + + + + + +-9072027 +-9072027 +-9072027 +x +y +Texts for North Carolina diff --git a/tests/testthat/test-coord_sf.R b/tests/testthat/test-coord_sf.R index 34c9ccbbc5..77cb8a9313 100644 --- a/tests/testthat/test-coord_sf.R +++ b/tests/testthat/test-coord_sf.R @@ -3,16 +3,20 @@ context("coord_sf") test_that("basic plot builds without error", { skip_if_not_installed("sf") - nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) - plot <- ggplot(nc) + - geom_sf() + - coord_sf() + nc_tiny_coords <- matrix( + c(-81.473, -81.741, -81.67, -81.345, -81.266, -81.24, -81.473, + 36.234, 36.392, 36.59, 36.573, 36.437, 36.365, 36.234), + ncol = 2 + ) - # Perform minimal test as long as vdiffr test is disabled - expect_error(regexp = NA, ggplot_build(plot)) + nc <- sf::st_as_sf( + data_frame( + NAME = "ashe", + geometry = sf::st_sfc(sf::st_polygon(list(nc_tiny_coords)), crs = 4326) + ) + ) - skip("sf tests are currently unstable") - expect_doppelganger("sf-polygons", plot) + expect_doppelganger("sf-polygons", ggplot(nc) + geom_sf() + coord_sf()) }) test_that("graticule lines can be removed via theme", { diff --git a/tests/testthat/test-geom-sf.R b/tests/testthat/test-geom-sf.R index c46d6a2e82..eb1c2aa54f 100644 --- a/tests/testthat/test-geom-sf.R +++ b/tests/testthat/test-geom-sf.R @@ -7,21 +7,25 @@ test_that("geom_sf draws correctly", { skip_if_not_installed("sf") if (packageVersion("sf") < "0.5.3") skip("Need sf 0.5.3") - f <- system.file("gpkg/nc.gpkg", package="sf") - nc <- sf::read_sf(f) + nc_tiny_coords <- matrix( + c(-81.473, -81.741, -81.67, -81.345, -81.266, -81.24, -81.473, + 36.234, 36.392, 36.59, 36.573, 36.437, 36.365, 36.234), + ncol = 2 + ) + nc <- sf::st_as_sf( + data_frame( + NAME = "ashe", + geometry = sf::st_sfc(sf::st_polygon(list(nc_tiny_coords)), crs = 4326) + ) + ) - # Perform minimal tests as long as vdiffr tests are disabled - plot <- ggplot() + geom_sf(data = nc) - expect_error(regexp = NA, ggplot_build(plot)) + # Perform minimal tests pts <- sf::st_sf(a = 1:2, geometry = sf::st_sfc(sf::st_point(0:1), sf::st_point(1:2))) plot <- ggplot() + geom_sf(data = pts) expect_error(regexp = NA, ggplot_build(plot)) - - skip("sf tests are currently unstable") - expect_doppelganger("North Carolina county boundaries", ggplot() + geom_sf(data = nc) + coord_sf(datum = 4326) ) @@ -36,25 +40,27 @@ test_that("geom_sf_text() and geom_sf_label() draws correctly", { skip_if_not_installed("sf") if (packageVersion("sf") < "0.5.3") skip("Need sf 0.5.3") - f <- system.file("gpkg/nc.gpkg", package="sf") - nc <- sf::read_sf(f) - # In order to avoid warning, trnasform to a projected coordinate system + nc_tiny_coords <- matrix( + c(-81.473, -81.741, -81.67, -81.345, -81.266, -81.24, -81.473, + 36.234, 36.392, 36.59, 36.573, 36.437, 36.365, 36.234), + ncol = 2 + ) + + nc <- sf::st_as_sf( + data_frame( + NAME = "ashe", + geometry = sf::st_sfc(sf::st_polygon(list(nc_tiny_coords)), crs = 4326) + ) + ) + + # In order to avoid warning, transform to a projected coordinate system nc_3857 <- sf::st_transform(nc, "+init=epsg:3857") - # Perform minimal tests as long as vdiffr tests are disabled - plot <- ggplot() + geom_sf_text(data = nc_3857[1:3, ], aes(label = NAME)) - expect_error(regexp = NA, ggplot_build(plot)) - - plot <- ggplot() + geom_sf_label(data = nc_3857[1:3, ], aes(label = NAME)) - expect_error(regexp = NA, ggplot_build(plot)) - - skip("sf tests are currently unstable") - expect_doppelganger("Texts for North Carolina", - ggplot() + geom_sf_text(data = nc_3857[1:3, ], aes(label = NAME)) + ggplot() + geom_sf_text(data = nc_3857, aes(label = NAME)) ) expect_doppelganger("Labels for North Carolina", - ggplot() + geom_sf_label(data = nc_3857[1:3, ], aes(label = NAME)) + ggplot() + geom_sf_label(data = nc_3857, aes(label = NAME)) ) })