Skip to content

Flip radius axis in coord_radial() when position = "right"/"top" #5748

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 5 commits into from
Apr 2, 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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 (#5735)
* The default behaviour of `resolution()` has been reverted to pre-3.5.0
behaviour. Whether mapped discrete vectors should be treated as having
resolution of 1 is controlled by the new `discrete` argument.
Expand Down
17 changes: 14 additions & 3 deletions R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,18 @@ CoordRadial <- ggproto("CoordRadial", Coord,
guide_params[["theta"]]$position <- "theta"
guide_params[["theta.sec"]]$position <- "theta.sec"

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) {

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)
}
Expand All @@ -182,8 +189,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)
Expand Down