Skip to content

Commit 03a50ac

Browse files
authored
Switch position of all scales in layout if coord_flip (#1790)
1 parent bc9e69f commit 03a50ac

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

R/layout.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,15 @@ Layout <- ggproto("Layout", NULL,
128128
# TODO: change coord_train method to take individual x and y scales
129129
coord$train(list(x = self$panel_scales$x[[ix]], y = self$panel_scales$y[[iy]]))
130130
}
131-
131+
# Switch position of all scales if CoordFlip
132+
if (inherits(coord, "CoordFlip")) {
133+
lapply(self$panel_scales$x, function(scale) {
134+
scale$position <- if (scale$position == "top") "bottom" else "top"
135+
})
136+
lapply(self$panel_scales$y, function(scale) {
137+
scale$position <- if (scale$position == "left") "right" else "left"
138+
})
139+
}
132140
self$panel_ranges <- Map(compute_range, self$panel_layout$SCALE_X, self$panel_layout$SCALE_Y)
133141
},
134142

0 commit comments

Comments
 (0)