diff --git a/NEWS.md b/NEWS.md index c460be148b..0969633a9e 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). * Fixed spurious warnings when the `weight` was used in `stat_bin_2d()`, `stat_boxplot()`, `stat_contour()`, `stat_bin_hex()` and `stat_quantile()` (@teunbrand, #5216). 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]),