From 5f2a6602407ea3683dd3ce1a0a58591ef5abba8d Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 13 Mar 2023 22:33:16 +0100 Subject: [PATCH 1/2] only draw ticks when range is finite --- R/annotation-logticks.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/annotation-logticks.R b/R/annotation-logticks.R index 8d42734748..dfd9138167 100644 --- a/R/annotation-logticks.R +++ b/R/annotation-logticks.R @@ -135,7 +135,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom, mid <- convertUnit(mid, "cm", valueOnly = TRUE) long <- convertUnit(long, "cm", valueOnly = TRUE) - if (grepl("[b|t]", sides)) { + if (grepl("[b|t]", sides) && all(is.finite(panel_params$x.range))) { # Get positions of x tick marks xticks <- calc_logticks( @@ -175,7 +175,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom, } } - if (grepl("[l|r]", sides)) { + if (grepl("[l|r]", sides) && all(is.finite(panel_params$y.range))) { yticks <- calc_logticks( base = base, minpow = floor(panel_params$y.range[1]), From 1e6a87c338200f3e6376a4dc4761017525768ab0 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Mon, 13 Mar 2023 22:34:44 +0100 Subject: [PATCH 2/2] Add NEWS bullet --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index fa3e327774..117e24a09e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # ggplot2 (development version) +* `annotation_logticks()` skips drawing ticks when the scale range is non-finite + instead of throwing an error (@teunbrand, #5229). * The `layer_data()`, `layer_scales()` and `layer_grob()` now have the default `plot = last_plot()` (@teunbrand, #5166). * To prevent changing the plotting order, `stat_sf()` is now computed per panel