@@ -659,7 +659,8 @@ Guides <- ggproto(
659
659
if (! stretch_spacing ) {
660
660
spacing <- convertWidth(spacing , " cm" )
661
661
}
662
- heights <- unit(height_cm(lapply(heights , sum )), " cm" )
662
+
663
+ total_height <- max(inject(unit.c(!!! lapply(heights , sum ))))
663
664
664
665
if (stretch_x || stretch_spacing ) {
665
666
widths <- redistribute_null_units(widths , spacing , margin , " width" )
@@ -672,14 +673,14 @@ Guides <- ggproto(
672
673
# Set global justification
673
674
vp <- viewport(
674
675
x = global_xjust , y = global_yjust , just = global_just ,
675
- height = max( heights ) ,
676
+ height = total_height ,
676
677
width = vp_width
677
678
)
678
679
679
680
# Initialise gtable as legends in a row
680
681
guides <- gtable_row(
681
682
name = " guides" , grobs = grobs ,
682
- widths = widths , height = max( heights ) ,
683
+ widths = widths , height = total_height ,
683
684
vp = vp
684
685
)
685
686
@@ -701,7 +702,7 @@ Guides <- ggproto(
701
702
if (! stretch_spacing ) {
702
703
spacing <- convertWidth(spacing , " cm" )
703
704
}
704
- widths <- unit(width_cm( lapply(widths , sum )), " cm " )
705
+ total_width <- max(inject(unit.c( !!! lapply(widths , sum ))) )
705
706
706
707
if (stretch_y || stretch_spacing ) {
707
708
heights <- redistribute_null_units(heights , spacing , margin , " height" )
@@ -715,13 +716,13 @@ Guides <- ggproto(
715
716
vp <- viewport(
716
717
x = global_xjust , y = global_yjust , just = global_just ,
717
718
height = vp_height ,
718
- width = max( widths )
719
+ width = total_width
719
720
)
720
721
721
722
# Initialise gtable as legends in a column
722
723
guides <- gtable_col(
723
724
name = " guides" , grobs = grobs ,
724
- width = max( widths ) , heights = heights ,
725
+ width = total_width , heights = heights ,
725
726
vp = vp
726
727
)
727
728
0 commit comments