Skip to content

Commit ff2e38f

Browse files
Handle guide positions
1 parent 7b85fd0 commit ff2e38f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

R/layout.R

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,17 @@ Layout <- ggproto("Layout", NULL,
241241
} %|W|% labels$sec.x
242242
if (is.derived(secondary)) secondary <- primary
243243
secondary <- self$panel_scales_x[[1]]$make_sec_title(secondary)
244-
list(primary = primary, secondary = secondary)[self$panel_scales_x[[1]]$axis_order()]
244+
ord <- c("primary", "secondary")
245+
scale_pos_reversed <- self$panel_scales_x[[1]]$position %in% c("right", "bottom")
246+
if (!is.null(self$panel_params[[1]]$guides) && length(self$panel_params[[1]]$guides) >= 1) {
247+
guides_pos_reversed <- self$panel_params[[1]]$guides[[1]]$position %in% c("right", "bottom")
248+
} else {
249+
guides_pos_reversed <- TRUE
250+
}
251+
if (scale_pos_reversed && guides_pos_reversed) {
252+
ord <- rev(ord)
253+
}
254+
list(primary = primary, secondary = secondary)[ord]
245255
},
246256

247257
ylabel = function(self, labels) {
@@ -254,7 +264,17 @@ Layout <- ggproto("Layout", NULL,
254264
} %|W|% labels$sec.y
255265
if (is.derived(secondary)) secondary <- primary
256266
secondary <- self$panel_scales_y[[1]]$make_sec_title(secondary)
257-
list(primary = primary, secondary = secondary)[self$panel_scales_y[[1]]$axis_order()]
267+
ord <- c("primary", "secondary")
268+
scale_pos_reversed <- self$panel_scales_y[[1]]$position %in% c("right", "bottom")
269+
if (!is.null(self$panel_params[[1]]$guides) && length(self$panel_params[[1]]$guides) >= 2) {
270+
guides_pos_reversed <- self$panel_params[[1]]$guides[[2]]$position %in% c("right", "bottom")
271+
} else {
272+
guides_pos_reversed <- FALSE
273+
}
274+
if (scale_pos_reversed || guides_pos_reversed) {
275+
ord <- rev(ord)
276+
}
277+
list(primary = primary, secondary = secondary)[ord]
258278
},
259279

260280
render_labels = function(self, labels, theme) {

0 commit comments

Comments
 (0)