diff --git a/NEWS.md b/NEWS.md
index c587911c83..1d4344dc5e 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -278,6 +278,9 @@
than `origin`, following in `stat_bin()`'s footsteps (@teunbrand).
* `stat_summary_2d()` and `stat_bin_2d()` now deal with zero-range data
more elegantly (@teunbrand, #6207).
+* Munching in `coord_polar()` and `coord_radial()` now adds more detail,
+ particularly for data-points with a low radius near the center
+ (@teunbrand, #5023).
# ggplot2 3.5.1
diff --git a/R/coord-polar.R b/R/coord-polar.R
index de9453ddb9..b8855f52b9 100644
--- a/R/coord-polar.R
+++ b/R/coord-polar.R
@@ -84,7 +84,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
is_free = function() TRUE,
- distance = function(self, x, y, details) {
+ distance = function(self, x, y, details, boost = 0.75) {
arc <- self$start + c(0, 2 * pi)
dir <- self$direction
if (self$theta == "x") {
@@ -94,8 +94,8 @@ CoordPolar <- ggproto("CoordPolar", Coord,
r <- rescale(x, from = details$r.range)
theta <- theta_rescale_no_clip(y, details$theta.range, arc, dir)
}
-
- dist_polar(r, theta)
+ # The ^boost boosts detailed munching when r is small
+ dist_polar(r^boost, theta)
},
backtransform_range = function(self, panel_params) {
diff --git a/R/coord-radial.R b/R/coord-radial.R
index 1fea09dcde..ef6130fb34 100644
--- a/R/coord-radial.R
+++ b/R/coord-radial.R
@@ -120,7 +120,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
is_free = function() TRUE,
- distance = function(self, x, y, details) {
+ distance = function(self, x, y, details, boost = 0.75) {
arc <- details$arc %||% c(0, 2 * pi)
if (self$theta == "x") {
r <- rescale(y, from = details$r.range, to = self$inner_radius / 0.4)
@@ -129,8 +129,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
r <- rescale(x, from = details$r.range, to = self$inner_radius / 0.4)
theta <- theta_rescale_no_clip(y, details$theta.range, arc)
}
-
- dist_polar(r, theta)
+ # The ^boost boosts detailed munching when r is small
+ dist_polar(r^boost, theta)
},
backtransform_range = function(self, panel_params) {
diff --git a/tests/testthat/_snaps/coord-polar/bottom-half-circle-with-rotated-text.svg b/tests/testthat/_snaps/coord-polar/bottom-half-circle-with-rotated-text.svg
index c01f91abbc..6349bcb350 100644
--- a/tests/testthat/_snaps/coord-polar/bottom-half-circle-with-rotated-text.svg
+++ b/tests/testthat/_snaps/coord-polar/bottom-half-circle-with-rotated-text.svg
@@ -33,8 +33,8 @@
-
-
+
+
diff --git a/tests/testthat/_snaps/coord-polar/full-circle-with-axes-placed-at-90-and-225-degrees.svg b/tests/testthat/_snaps/coord-polar/full-circle-with-axes-placed-at-90-and-225-degrees.svg
index 497db8dcf4..46607ddecd 100644
--- a/tests/testthat/_snaps/coord-polar/full-circle-with-axes-placed-at-90-and-225-degrees.svg
+++ b/tests/testthat/_snaps/coord-polar/full-circle-with-axes-placed-at-90-and-225-degrees.svg
@@ -29,15 +29,15 @@
-
-
-
+
+
+
-
-
+
+
diff --git a/tests/testthat/_snaps/coord-polar/inner-radius-with-all-axes.svg b/tests/testthat/_snaps/coord-polar/inner-radius-with-all-axes.svg
index b75d829d47..7fddfe8e83 100644
--- a/tests/testthat/_snaps/coord-polar/inner-radius-with-all-axes.svg
+++ b/tests/testthat/_snaps/coord-polar/inner-radius-with-all-axes.svg
@@ -28,26 +28,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
@@ -97,8 +97,8 @@
-
-
+
+
10
15
20
@@ -111,7 +111,7 @@
-
+
diff --git a/tests/testthat/_snaps/coord-polar/partial-with-all-axes.svg b/tests/testthat/_snaps/coord-polar/partial-with-all-axes.svg
index 03d06791cf..2f1de17be0 100644
--- a/tests/testthat/_snaps/coord-polar/partial-with-all-axes.svg
+++ b/tests/testthat/_snaps/coord-polar/partial-with-all-axes.svg
@@ -28,26 +28,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -105,8 +105,8 @@
-
-
+
+
100
200
300
@@ -115,7 +115,7 @@
-
+
diff --git a/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-has-center-hole.svg b/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-has-center-hole.svg
index 8bf3cc6ec2..60045c846f 100644
--- a/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-has-center-hole.svg
+++ b/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-has-center-hole.svg
@@ -44,9 +44,9 @@
-
-
-
+
+
+
1
2
0/3
diff --git a/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-no-center-hole.svg b/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-no-center-hole.svg
index d145a1e446..32bb41821f 100644
--- a/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-no-center-hole.svg
+++ b/tests/testthat/_snaps/coord-polar/racetrack-plot-closed-and-no-center-hole.svg
@@ -44,9 +44,9 @@
-
-
-
+
+
+
1
2
0/3
diff --git a/tests/testthat/_snaps/coord-polar/rays-circular-arcs-and-spiral-arcs.svg b/tests/testthat/_snaps/coord-polar/rays-circular-arcs-and-spiral-arcs.svg
index dfc63cb3d9..0c255f0bb8 100644
--- a/tests/testthat/_snaps/coord-polar/rays-circular-arcs-and-spiral-arcs.svg
+++ b/tests/testthat/_snaps/coord-polar/rays-circular-arcs-and-spiral-arcs.svg
@@ -47,115 +47,130 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -303,32 +318,32 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/testthat/_snaps/coord-polar/rose-plot-with-has-equal-spacing.svg b/tests/testthat/_snaps/coord-polar/rose-plot-with-has-equal-spacing.svg
index b9d09b1835..c82603f417 100644
--- a/tests/testthat/_snaps/coord-polar/rose-plot-with-has-equal-spacing.svg
+++ b/tests/testthat/_snaps/coord-polar/rose-plot-with-has-equal-spacing.svg
@@ -44,8 +44,8 @@
-
-
+
+
A
B
diff --git a/tests/testthat/_snaps/coord-polar/three-concentric-circles.svg b/tests/testthat/_snaps/coord-polar/three-concentric-circles.svg
index e00a3d6a7c..b54b3afc35 100644
--- a/tests/testthat/_snaps/coord-polar/three-concentric-circles.svg
+++ b/tests/testthat/_snaps/coord-polar/three-concentric-circles.svg
@@ -47,8 +47,8 @@
-
-
+
+
0.25
0.50
diff --git a/tests/testthat/_snaps/geom-hline-vline-abline/polar-lines-intersect-mid-bars.svg b/tests/testthat/_snaps/geom-hline-vline-abline/polar-lines-intersect-mid-bars.svg
index 2f67080988..4bd4970011 100644
--- a/tests/testthat/_snaps/geom-hline-vline-abline/polar-lines-intersect-mid-bars.svg
+++ b/tests/testthat/_snaps/geom-hline-vline-abline/polar-lines-intersect-mid-bars.svg
@@ -36,10 +36,10 @@
-
-
-
-
+
+
+
+
@@ -47,8 +47,8 @@
-
-
+
+
A
B
C
diff --git a/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg b/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg
index b970c9f317..5080746f6c 100644
--- a/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg
+++ b/tests/testthat/_snaps/geom-polygon/open-and-closed-munched-polygons.svg
@@ -25,10 +25,10 @@
-
-
-
-
+
+
+
+
colour
diff --git a/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg b/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg
index efb96b5c87..9a3ee13ab3 100644
--- a/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg
+++ b/tests/testthat/_snaps/geom-raster/rectangle-fallback.svg
@@ -36,10 +36,10 @@
-
-
-
-
+
+
+
+
1.0
1.5
2.0
diff --git a/tests/testthat/_snaps/geom-violin/coord-polar.svg b/tests/testthat/_snaps/geom-violin/coord-polar.svg
index 02ae1107df..5da2c31990 100644
--- a/tests/testthat/_snaps/geom-violin/coord-polar.svg
+++ b/tests/testthat/_snaps/geom-violin/coord-polar.svg
@@ -38,7 +38,7 @@
-
+
A
B
C
diff --git a/tests/testthat/_snaps/guide-axis/guide-axis-theta-with-angle-adapting-to-theta.svg b/tests/testthat/_snaps/guide-axis/guide-axis-theta-with-angle-adapting-to-theta.svg
index 48b903c6f3..79f3e27b8c 100644
--- a/tests/testthat/_snaps/guide-axis/guide-axis-theta-with-angle-adapting-to-theta.svg
+++ b/tests/testthat/_snaps/guide-axis/guide-axis-theta-with-angle-adapting-to-theta.svg
@@ -28,53 +28,53 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -176,8 +176,8 @@
-
-
+
+
10
15
20
diff --git a/tests/testthat/_snaps/guide-axis/stacked-radial-axes.svg b/tests/testthat/_snaps/guide-axis/stacked-radial-axes.svg
index 9b4cf580e7..d8399aeb76 100644
--- a/tests/testthat/_snaps/guide-axis/stacked-radial-axes.svg
+++ b/tests/testthat/_snaps/guide-axis/stacked-radial-axes.svg
@@ -28,21 +28,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -95,15 +95,15 @@
-
+
100
200
300
-
-
+
+
100
200
300
@@ -112,7 +112,7 @@
-
+
100
200
300
@@ -121,7 +121,7 @@
-
+
@@ -130,7 +130,7 @@
200
300
400
-
+
diff --git a/tests/testthat/test-coord-polar.R b/tests/testthat/test-coord-polar.R
index 2b07d96b21..1f662d2322 100644
--- a/tests/testthat/test-coord-polar.R
+++ b/tests/testthat/test-coord-polar.R
@@ -9,7 +9,7 @@ test_that("polar distance is calculated correctly", {
)
coord <- coord_polar()
panel_params <- coord$setup_panel_params(scales$x, scales$y)
- dists <- coord$distance(dat$theta, dat$r, panel_params)
+ dists <- coord$distance(dat$theta, dat$r, panel_params, boost = 1)
# dists is normalized by dividing by this value, so we'll add it back
# The maximum length of a spiral arc, from (t,r) = (0,0) to (2*pi,1)