@@ -244,35 +244,39 @@ Layout <- ggproto("Layout", NULL,
244244 },
245245
246246 resolve_label = function (self , scale , labels ) {
247- # General order is: guide title > scale name > labels
248- aes <- scale $ aesthetics [[1 ]]
249- primary <- scale $ name %| W | % labels [[aes ]]
250- secondary <- if (is.null(scale $ secondary.axis )) {
251- waiver()
252- } else {
253- scale $ sec_name()
254- } %| W | % labels [[paste0(" sec." , aes )]]
255- if (is.derived(secondary )) secondary <- primary
247+ aes <- scale $ aesthetics [[1 ]]
248+
249+ prim_scale <- scale $ name
250+ seco_scale <- (scale $ sec_name %|| % waiver )()
251+
252+ prim_label <- labels [[aes ]]
253+ seco_label <- labels [[paste0(" sec. aes" )]]
254+
255+ prim_guide <- seco_guide <- waiver()
256+
256257 order <- scale $ axis_order()
257258
258- if (! is.null(self $ panel_params [[1 ]]$ guides )) {
259- if ((scale $ position ) %in% c(" left" , " right" )) {
260- guides <- c(" y" , " y.sec" )
261- } else {
262- guides <- c(" x" , " x.sec" )
263- }
264- params <- self $ panel_params [[1 ]]$ guides $ get_params(guides )
259+ panel <- self $ panel_params [[1 ]]$ guides
260+ if (! is.null(panel )) {
261+ position <- scale $ position
262+ aes <- switch (position , left = , right = " y" , " x" )
263+ params <- panel $ get_params(paste0(aes , c(" " , " .sec" )))
265264 if (! is.null(params )) {
266- primary <- params [[1 ]]$ title % | W | % primary
267- secondary <- params [[2 ]]$ title % | W | % secondary
268- position <- params [[ 1 ]] $ position % || % scale $ position
269- if (position != scale $ position ) {
265+ prim_guide <- params [[1 ]]$ title
266+ seco_guide <- params [[2 ]]$ title
267+ position <- scale $ position
268+ if (( params [[ 1 ]] $ position % || % position ) != position ) {
270269 order <- rev(order )
271270 }
272271 }
273272 }
274- primary <- scale $ make_title(primary )
275- secondary <- scale $ make_sec_title(secondary )
273+
274+ primary <- scale $ make_title(prim_guide , prim_scale , prim_label )
275+ secondary <- scale $ make_sec_title(seco_guide , seco_scale , seco_label )
276+ if (is.derived(secondary )) {
277+ secondary <- primary
278+ }
279+
276280 list (primary = primary , secondary = secondary )[order ]
277281 },
278282
0 commit comments