@@ -653,11 +653,14 @@ Guides <- ggproto(
653653 height = heightDetails(grobs [[i ]]))
654654 )
655655 }
656-
657- spacing <- convertWidth(theme $ legend.spacing.x , " cm" )
656+ spacing <- theme $ legend.spacing.x
657+ stretch_spacing <- any(unitType(spacing ) == " null" )
658+ if (! stretch_spacing ) {
659+ spacing <- convertWidth(spacing , " cm" )
660+ }
658661 heights <- unit(height_cm(lapply(heights , sum )), " cm" )
659662
660- if (stretch_x ) {
663+ if (stretch_x || stretch_spacing ) {
661664 widths <- redistribute_null_units(widths , spacing , margin , " width" )
662665 vp_width <- unit(1 , " npc" )
663666 } else {
@@ -692,10 +695,14 @@ Guides <- ggproto(
692695 )
693696 }
694697
695- spacing <- convertHeight(theme $ legend.spacing.y , " cm" )
698+ spacing <- theme $ legend.spacing.y
699+ stretch_spacing <- any(unitType(spacing ) == " null" )
700+ if (! stretch_spacing ) {
701+ spacing <- convertWidth(spacing , " cm" )
702+ }
696703 widths <- unit(width_cm(lapply(widths , sum )), " cm" )
697704
698- if (stretch_y ) {
705+ if (stretch_y || stretch_spacing ) {
699706 heights <- redistribute_null_units(heights , spacing , margin , " height" )
700707 vp_height <- unit(1 , " npc" )
701708 } else {
0 commit comments