From e16ae8b600180c1b3d95a0da39bdaa3e43296373 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 10 Dec 2024 13:56:10 +0100 Subject: [PATCH 1/5] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index dd574ac1aa..e693301d99 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* Attempt to boost detail in `coord_polar()` and `coord_radial()` near the + center (@teunbrand, #5023) * `guide_*()` can now accept two inside legend theme elements: `legend.position.inside` and `legend.justification.inside`, allowing inside legends to be placed at different positions. Only inside legends with the same From 4e2481d82a7283f9842ebf65f744f0042f9bae06 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Dec 2024 16:30:56 +0100 Subject: [PATCH 2/5] fallback --- R/coord-sf.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/R/coord-sf.R b/R/coord-sf.R index 3f96ff6aaf..9e3fb6eac6 100644 --- a/R/coord-sf.R +++ b/R/coord-sf.R @@ -721,6 +721,14 @@ view_scales_from_graticule <- function(graticule, scale, aesthetic, accept_start <- graticule[[orth_start]] < thres accept_end <- graticule[[orth_end]] < thres } + if (!any(accept_start | accept_end)) { + eps <- sqrt(.Machine$double.xmin) + subtract <- switch(position, top = , bottom = 90, 0) + straight <- + abs(graticule$angle_start - subtract) < eps & + abs(graticule$angle_end - subtract) < eps + accept_start <- accept_end <- straight + } # Parsing the information of the `label_axes` argument: # should we label the meridians ("E") or parallels ("N")? From af716a761db605faff8c3d8d31998e376b851326 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Dec 2024 16:35:13 +0100 Subject: [PATCH 3/5] avoid duplicated labels --- R/coord-sf.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/coord-sf.R b/R/coord-sf.R index 9e3fb6eac6..d603d57de7 100644 --- a/R/coord-sf.R +++ b/R/coord-sf.R @@ -727,7 +727,7 @@ view_scales_from_graticule <- function(graticule, scale, aesthetic, straight <- abs(graticule$angle_start - subtract) < eps & abs(graticule$angle_end - subtract) < eps - accept_start <- accept_end <- straight + accept_start <- straight } # Parsing the information of the `label_axes` argument: From b5e923b846fb8c8145c8c25157553eff98ece387 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Dec 2024 16:36:11 +0100 Subject: [PATCH 4/5] add test --- tests/testthat/test-coord_sf.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/testthat/test-coord_sf.R b/tests/testthat/test-coord_sf.R index 516d2fa9ec..a684bea20b 100644 --- a/tests/testthat/test-coord_sf.R +++ b/tests/testthat/test-coord_sf.R @@ -425,3 +425,15 @@ test_that("coord_sf() can render with empty graticules", { p <- suppressWarnings(layer_grob(ggplot(df) + geom_sf())[[1]]) expect_length(p$x, 1) }) + +test_that("coord_sf() can calculate breaks when expansion is on", { + skip_if_not_installed("sf") + df <- sf::st_multipoint(cbind(c(-180, 180), c(-90, 90))) + df <- sf::st_sfc(df, crs = 4326) + b <- ggplot_build(ggplot(df) + geom_sf()) + + x <- get_guide_data(b, "x") + y <- get_guide_data(b, "y") + expect_equal(nrow(x), 5L) + expect_equal(nrow(y), 3L) +}) From ea230a4a7cee2769fd7902982c7dc4bd7f581bda Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 11 Dec 2024 16:38:30 +0100 Subject: [PATCH 5/5] add news bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index e693301d99..999ea93b3f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* Axis labels are now preserved better when using `coord_sf(expand = TRUE)` and + graticule lines are straight but do not meet the edge (@teunbrand, #2985). * Attempt to boost detail in `coord_polar()` and `coord_radial()` near the center (@teunbrand, #5023) * `guide_*()` can now accept two inside legend theme elements: