Skip to content

Amend #6070 #6381

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions R/coord-cartesian-.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
self$range(panel_params)
},

transform = function(self, data, panel_params) {
reverse <- self$reverse %||% "none"
transform = function(data, panel_params) {
reverse <- panel_params$reverse %||% "none"
x <- panel_params$x[[switch(reverse, xy = , x = "reverse", "rescale")]]
y <- panel_params$y[[switch(reverse, xy = , y = "reverse", "rescale")]]
data <- transform_position(data, x, y)
Expand All @@ -113,7 +113,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
c(
view_scales_from_scale(scale_x, self$limits$x, params$expand[c(4, 2)]),
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)])
view_scales_from_scale(scale_y, self$limits$y, params$expand[c(3, 1)]),
reverse = self$reverse %||% "none"
)
},

Expand Down
1 change: 1 addition & 0 deletions R/coord-radial.R
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ polar_bbox <- function(arc, margin = c(0.05, 0.05, 0.05, 0.05),
return(list(x = c(0, 1), y = c(0, 1)))
}
arc <- sort(arc)
inner_radius <- sort(inner_radius)

# X and Y position of the sector arc ends
xmax <- 0.5 * sin(arc) + 0.5
Expand Down
5 changes: 3 additions & 2 deletions R/coord-sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
target_crs <- panel_params$crs

# CoordSf doesn't use the viewscale rescaling, so we just flip ranges
reverse <- self$reverse %||% "none"
reverse <- panel_params$reverse %||% "none"
x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x_range)
y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y_range)

Expand Down Expand Up @@ -268,7 +268,8 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
y_range = y_range,
crs = params$crs,
default_crs = params$default_crs,
!!!viewscales
!!!viewscales,
reverse = self$reverse %||% "none"
)

# Rescale graticule for panel grid
Expand Down
5 changes: 3 additions & 2 deletions R/coord-transform.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ CoordTrans <- ggproto("CoordTrans", Coord,
transform = function(self, data, panel_params) {
# trans_x() and trans_y() needs to keep Inf values because this can be called
# in guide_transform.axis()
reverse <- self$reverse %||% "none"
reverse <- panel_params$reverse %||% "none"
x_range <- switch(reverse, xy = , x = rev, identity)(panel_params$x.range)
y_range <- switch(reverse, xy = , y = rev, identity)(panel_params$y.range)
trans_x <- function(data) {
Expand All @@ -159,7 +159,8 @@ CoordTrans <- ggproto("CoordTrans", Coord,
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
c(
view_scales_from_scale_with_coord_trans(scale_x, self$limits$x, self$trans$x, params$expand[c(4, 2)]),
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)])
view_scales_from_scale_with_coord_trans(scale_y, self$limits$y, self$trans$y, params$expand[c(3, 1)]),
reverse = self$reverse %||% "none"
)
},

Expand Down
24 changes: 14 additions & 10 deletions R/guide-axis.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,36 @@ GuideAxis <- ggproto(
}

opposite <- setdiff(c("x", "y"), aesthetic)
opposite_value <- if (position %in% c("top", "right")) -Inf else Inf

data_frame(
!!aesthetic := value,
!!opposite := opposite_value
)
data_frame(!!aesthetic := value)
},

transform = function(self, params, coord, panel_params) {
key <- params$key
position <- params$position
check <- FALSE

aesthetic <- names(key)[!grepl("^\\.", names(key))]
ortho <- setdiff(c("x", "y"), params$aesthetic)
override <- switch(position %||% "", bottom = , left = -Inf, Inf)

if (!(panel_params$reverse %||% "none") %in% c("xy", ortho)) {
override <- -override
}

if (!(is.null(position) || nrow(key) == 0)) {
check <- TRUE
aesthetics <- names(key)[!grepl("^\\.", names(key))]
if (!all(c("x", "y") %in% aesthetics)) {
other_aesthetic <- setdiff(c("x", "y"), aesthetics)
override_value <- if (position %in% c("bottom", "left")) -Inf else Inf
key[[other_aesthetic]] <- override_value
if (!all(c("x", "y") %in% aesthetic)) {
key[[ortho]] <- override
}
key <- coord$transform(key, panel_params)
params$key <- key
}

if (!is.null(params$decor)) {
if (!ortho %in% names(params$decor)) {
params$decor[[ortho]] <- override
}
params$decor <- coord_munch(coord, params$decor, panel_params)

if (!coord$is_linear()) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions tests/testthat/_snaps/coord-polar/reversed-polar-coords.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading