Skip to content

Commit ac19272

Browse files
authored
Flip radius axis in coord_radial() when position = "right"/"top" (#5748)
* flip r axis mechanism * Add news bullet * forgot about the `modify_scales` method swapping positions
1 parent 60407ac commit ac19272

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
* Patterns and gradients are now also enabled in `geom_sf()`
2020
(@teunbrand, #5716).
2121
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
22+
* While axes in `coord_radial()` don't neatly fit the top/right/bottom/left
23+
organisation, specifying `position = "top"` or `position = "right"`
24+
in the scale will flip the placement of the radial axis (#5735)
2225
* The default behaviour of `resolution()` has been reverted to pre-3.5.0
2326
behaviour. Whether mapped discrete vectors should be treated as having
2427
resolution of 1 is controlled by the new `discrete` argument.

R/coord-radial.R

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,18 @@ CoordRadial <- ggproto("CoordRadial", Coord,
167167
guide_params[["theta"]]$position <- "theta"
168168
guide_params[["theta.sec"]]$position <- "theta.sec"
169169

170+
if (self$theta == "x") {
171+
opposite_r <- isTRUE(scales$r$position %in% c("top", "right"))
172+
} else {
173+
opposite_r <- isTRUE(scales$r$position %in% c("bottom", "left"))
174+
}
175+
170176
if (self$r_axis_inside) {
171177

172178
arc <- rad2deg(self$arc)
173179
r_position <- c("left", "right")
174-
if (self$direction == -1) {
180+
# If both opposite direction and opposite position, don't flip
181+
if (xor(self$direction == -1, opposite_r)) {
175182
arc <- rev(arc)
176183
r_position <- rev(r_position)
177184
}
@@ -182,8 +189,12 @@ CoordRadial <- ggproto("CoordRadial", Coord,
182189
guide_params[["r"]]$angle <- guide_params[["r"]]$angle %|W|% arc[1]
183190
guide_params[["r.sec"]]$angle <- guide_params[["r.sec"]]$angle %|W|% arc[2]
184191
} else {
185-
guide_params[["r"]]$position <- params$r_axis
186-
guide_params[["r.sec"]]$position <- opposite_position(params$r_axis)
192+
r_position <- c(params$r_axis, opposite_position(params$r_axis))
193+
if (opposite_r) {
194+
r_position <- rev(r_position)
195+
}
196+
guide_params[["r"]]$position <- r_position[1]
197+
guide_params[["r.sec"]]$position <- r_position[2]
187198
}
188199

189200
guide_params[drop_guides] <- list(NULL)

0 commit comments

Comments
 (0)