Skip to content
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
35 changes: 17 additions & 18 deletions R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ coord_radial <- function(theta = "x",
arc <- switch(reverse, thetar = , theta = rev(arc), arc)

r.axis.inside <- r.axis.inside %||% !(abs(arc[2] - arc[1]) >= 1.999 * pi)
if (isFALSE(r.axis.inside)) {
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, arc)
if (!any(place)) {
cli::cli_warn(c(
"No appropriate placement found for outside {.field r.axis}.",
i = "Will use {.code r.axis.inside = TRUE} instead"
))
r.axis.inside <- TRUE
}
}

inner.radius <- c(inner.radius, 1) * 0.4
inner.radius <- switch(reverse, thetar = , r = rev, identity)(inner.radius)
Expand Down Expand Up @@ -453,25 +463,14 @@ CoordRadial <- ggproto("CoordRadial", Coord,

setup_params = function(self, data) {
params <- ggproto_parent(Coord, self)$setup_params(data)
if (!isFALSE(self$r_axis_inside)) {
return(params)
}

place <- in_arc(c(0, 0.5, 1, 1.5) * pi, self$arc)
if (!any(place)) {
cli::cli_warn(c(
"No appropriate placement found for {.arg r_axis_inside}.",
i = "Axis will be placed at panel edge."
))
params$r_axis_inside <- TRUE
return(params)
if (isFALSE(self$r_axis_inside)) {
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, self$arc)
params$r_axis <- if (any(place[c(1, 3)])) "left" else "bottom"
params$fake_arc <- switch(
which(place[c(1, 3, 2, 4)])[1],
c(0, 2), c(1, 3), c(0.5, 2.5), c(1.5, 3.5)
) * pi
}

params$r_axis <- if (any(place[c(1, 3)])) "left" else "bottom"
params$fake_arc <- switch(
which(place[c(1, 3, 2, 4)])[1],
c(0, 2), c(1, 3), c(0.5, 2.5), c(1.5, 3.5)
) * pi
params
}
)
Expand Down
15 changes: 7 additions & 8 deletions man/coord_polar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/coord-polar.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

---

No appropriate placement found for `r_axis_inside`.
i Axis will be placed at panel edge.
No appropriate placement found for outside r.axis.
i Will use `r.axis.inside = TRUE` instead

# when both x and y are AsIs, they are not transformed

Expand Down