Skip to content

Commit 4b887b7

Browse files
authored
Tweak polar distance (#6226)
* add boosts to radius * tweak test * accept snapshots * add news bullet
1 parent e30642b commit 4b887b7

19 files changed

+306
-288
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@
278278
than `origin`, following in `stat_bin()`'s footsteps (@teunbrand).
279279
* `stat_summary_2d()` and `stat_bin_2d()` now deal with zero-range data
280280
more elegantly (@teunbrand, #6207).
281+
* Munching in `coord_polar()` and `coord_radial()` now adds more detail,
282+
particularly for data-points with a low radius near the center
283+
(@teunbrand, #5023).
281284

282285
# ggplot2 3.5.1
283286

R/coord-polar.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ CoordPolar <- ggproto("CoordPolar", Coord,
8484

8585
is_free = function() TRUE,
8686

87-
distance = function(self, x, y, details) {
87+
distance = function(self, x, y, details, boost = 0.75) {
8888
arc <- self$start + c(0, 2 * pi)
8989
dir <- self$direction
9090
if (self$theta == "x") {
@@ -94,8 +94,8 @@ CoordPolar <- ggproto("CoordPolar", Coord,
9494
r <- rescale(x, from = details$r.range)
9595
theta <- theta_rescale_no_clip(y, details$theta.range, arc, dir)
9696
}
97-
98-
dist_polar(r, theta)
97+
# The ^boost boosts detailed munching when r is small
98+
dist_polar(r^boost, theta)
9999
},
100100

101101
backtransform_range = function(self, panel_params) {

R/coord-radial.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ CoordRadial <- ggproto("CoordRadial", Coord,
120120

121121
is_free = function() TRUE,
122122

123-
distance = function(self, x, y, details) {
123+
distance = function(self, x, y, details, boost = 0.75) {
124124
arc <- details$arc %||% c(0, 2 * pi)
125125
if (self$theta == "x") {
126126
r <- rescale(y, from = details$r.range, to = self$inner_radius / 0.4)
@@ -129,8 +129,8 @@ CoordRadial <- ggproto("CoordRadial", Coord,
129129
r <- rescale(x, from = details$r.range, to = self$inner_radius / 0.4)
130130
theta <- theta_rescale_no_clip(y, details$theta.range, arc)
131131
}
132-
133-
dist_polar(r, theta)
132+
# The ^boost boosts detailed munching when r is small
133+
dist_polar(r^boost, theta)
134134
},
135135

136136
backtransform_range = function(self, panel_params) {

tests/testthat/_snaps/coord-polar/bottom-half-circle-with-rotated-text.svg

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)