diff --git a/R/coord-radial.R b/R/coord-radial.R index 8df50bcb1e..3cef9c2b5b 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -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) @@ -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 } ) diff --git a/man/coord_polar.Rd b/man/coord_polar.Rd index 23bbcb97ea..3bc579bcbc 100644 --- a/man/coord_polar.Rd +++ b/man/coord_polar.Rd @@ -138,14 +138,13 @@ ggplot(mtcars, aes(disp, mpg)) + # Similar with coord_cartesian(), you can set limits. ggplot(mtcars, aes(disp, mpg)) + - geom_point() + - coord_radial( - start = -0.4 * pi, - end = 0.4 * pi, inner.radius = 0.3, - thetalim = c(200, 300), - rlim = c(15, 30), - clip = "on" - ) + geom_point() + + coord_radial( + start = -0.4 * pi, + end = 0.4 * pi, inner.radius = 0.3, + thetalim = c(200, 300), + rlim = c(15, 30), + ) } \seealso{ The \href{https://ggplot2-book.org/coord#polar-coordinates-with-coord_polar}{polar coordinates section} of the online ggplot2 book. diff --git a/tests/testthat/_snaps/coord-polar.md b/tests/testthat/_snaps/coord-polar.md index 62138ccf99..fcbe964bea 100644 --- a/tests/testthat/_snaps/coord-polar.md +++ b/tests/testthat/_snaps/coord-polar.md @@ -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