Skip to content

Fix coord_radial() full circle bug #5752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* Patterns and gradients are now also enabled in `geom_sf()`
(@teunbrand, #5716).
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
* Fixed bug in `coord_radial()` where full circles were not treated as such
(@teunbrand, #5750).
* When legends detect the presence of values in a layer, `NA` is now detected
if the data contains values outside the given breaks (@teunbrand, #5749).
* `annotate()` now warns about `stat` or `position` arguments (@teunbrand, #5151)
Expand Down
5 changes: 5 additions & 0 deletions R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,11 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
# For any `theta` in [0, 2 * pi), test if theta is inside the span
# given by `arc`
in_arc <- function(theta, arc) {
# Full circle case
if (abs(diff(arc)) > 2 * pi - sqrt(.Machine$double.eps)) {
return(rep(TRUE, length(theta)))
}
# Partial circle case
arc <- arc %% (2 * pi)
if (arc[1] < arc[2]) {
theta >= arc[1] & theta <= arc[2]
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-coord-polar.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ test_that("bounding box calculations are sensible", {
list(x = c(0, 1), y = c(0, 1))
)

# Full offset cirle
expect_equal(
polar_bbox(arc = c(2 * pi, 4 * pi)),
list(x = c(0, 1), y = c(0, 1))
)

# Right half of circle
expect_equal(
polar_bbox(arc = c(0, pi)),
Expand Down