@@ -241,7 +241,17 @@ Layout <- ggproto("Layout", NULL,
241
241
} %| W | % labels $ sec.x
242
242
if (is.derived(secondary )) secondary <- primary
243
243
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 ]
245
255
},
246
256
247
257
ylabel = function (self , labels ) {
@@ -254,7 +264,17 @@ Layout <- ggproto("Layout", NULL,
254
264
} %| W | % labels $ sec.y
255
265
if (is.derived(secondary )) secondary <- primary
256
266
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 ]
258
278
},
259
279
260
280
render_labels = function (self , labels , theme ) {
0 commit comments