From d915944029aa6512dd9fd3cd0a5d2450f494cc1f Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 5 Mar 2024 15:07:06 +0100 Subject: [PATCH 1/3] flip r axis mechanism --- R/coord-radial.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/R/coord-radial.R b/R/coord-radial.R index d4aefc979f..64b1460449 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -151,11 +151,14 @@ CoordRadial <- ggproto("CoordRadial", Coord, guide_params[["theta"]]$position <- "theta" guide_params[["theta.sec"]]$position <- "theta.sec" + opposite_r <- isTRUE(scales$r$position %in% c("top", "right")) + if (self$r_axis_inside) { arc <- rad2deg(self$arc) r_position <- c("left", "right") - if (self$direction == -1) { + # If both opposite direction and opposite position, don't flip + if (xor(self$direction == -1, opposite_r)) { arc <- rev(arc) r_position <- rev(r_position) } @@ -166,8 +169,12 @@ CoordRadial <- ggproto("CoordRadial", Coord, guide_params[["r"]]$angle <- guide_params[["r"]]$angle %|W|% arc[1] guide_params[["r.sec"]]$angle <- guide_params[["r.sec"]]$angle %|W|% arc[2] } else { - guide_params[["r"]]$position <- params$r_axis - guide_params[["r.sec"]]$position <- opposite_position(params$r_axis) + r_position <- c(params$r_axis, opposite_position(params$r_axis)) + if (opposite_r) { + r_position <- rev(r_position) + } + guide_params[["r"]]$position <- r_position[1] + guide_params[["r.sec"]]$position <- r_position[2] } guide_params[drop_guides] <- list(NULL) From 5dcaff790d2b99035a5246d4398900baf9779e97 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Tue, 5 Mar 2024 15:07:20 +0100 Subject: [PATCH 2/3] Add news bullet --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 3e5ba492ef..0c4cd6d435 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,9 @@ * Patterns and gradients are now also enabled in `geom_sf()` (@teunbrand, #5716). * `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665). +* While axes in `coord_radial()` don't neatly fit the top/right/bottom/left + organisation, specifying `position = "top"` or `position = "right"` + in the scale will flip the placement of the radial axis (#) # ggplot2 3.5.0 From c7193b3a002320748fbbcee7a1d92e8e2fa841f8 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Wed, 6 Mar 2024 13:40:41 +0100 Subject: [PATCH 3/3] forgot about the `modify_scales` method swapping positions --- R/coord-radial.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/coord-radial.R b/R/coord-radial.R index 64b1460449..f5b7f78a66 100644 --- a/R/coord-radial.R +++ b/R/coord-radial.R @@ -151,7 +151,11 @@ CoordRadial <- ggproto("CoordRadial", Coord, guide_params[["theta"]]$position <- "theta" guide_params[["theta.sec"]]$position <- "theta.sec" - opposite_r <- isTRUE(scales$r$position %in% c("top", "right")) + if (self$theta == "x") { + opposite_r <- isTRUE(scales$r$position %in% c("top", "right")) + } else { + opposite_r <- isTRUE(scales$r$position %in% c("bottom", "left")) + } if (self$r_axis_inside) {