@@ -536,28 +536,32 @@ GuideLegend <- ggproto(
536
536
)
537
537
heights <- head(vec_interleave(!!! heights ), - 1 )
538
538
539
- # Measure title
540
- title_width <- width_cm(grobs $ title )
541
- title_height <- height_cm(grobs $ title )
542
-
543
- # Combine title with rest of the sizes based on its position
544
- widths <- switch (
545
- params $ title.position ,
546
- " left" = c(title_width , hgap , widths ),
547
- " right" = c(widths , hgap , title_width ),
548
- c(widths , max(0 , title_width - sum(widths )))
549
- )
550
- heights <- switch (
551
- params $ title.position ,
552
- " top" = c(title_height , vgap , heights ),
553
- " bottom" = c(heights , vgap , title_height ),
554
- c(heights , max(0 , title_height - sum(heights )))
555
- )
539
+ has_title <- ! is.zero(grobs $ title )
540
+ if (has_title ) {
541
+ # Measure title
542
+ title_width <- width_cm(grobs $ title )
543
+ title_height <- height_cm(grobs $ title )
544
+
545
+ # Combine title with rest of the sizes based on its position
546
+ widths <- switch (
547
+ params $ title.position ,
548
+ " left" = c(title_width , hgap , widths ),
549
+ " right" = c(widths , hgap , title_width ),
550
+ c(widths , max(0 , title_width - sum(widths )))
551
+ )
552
+ heights <- switch (
553
+ params $ title.position ,
554
+ " top" = c(title_height , vgap , heights ),
555
+ " bottom" = c(heights , vgap , title_height ),
556
+ c(heights , max(0 , title_height - sum(heights )))
557
+ )
558
+ }
556
559
557
560
list (
558
561
widths = widths ,
559
562
heights = heights ,
560
- padding = elements $ padding
563
+ padding = elements $ padding ,
564
+ has_title = has_title
561
565
)
562
566
},
563
567
@@ -603,29 +607,34 @@ GuideLegend <- ggproto(
603
607
)
604
608
605
609
# Offset layout based on title position
606
- switch (
607
- params $ title.position ,
608
- " top" = {
609
- key_row <- key_row + 2
610
- label_row <- label_row + 2
611
- title_row <- 2
612
- title_col <- seq_along(sizes $ widths ) + 1
613
- },
614
- " bottom" = {
615
- title_row <- length(sizes $ heights ) + 1
616
- title_col <- seq_along(sizes $ widths ) + 1
617
- },
618
- " left" = {
619
- key_col <- key_col + 2
620
- label_col <- label_col + 2
621
- title_row <- seq_along(sizes $ heights ) + 1
622
- title_col <- 2
623
- },
624
- " right" = {
625
- title_row <- seq_along(sizes $ heights ) + 1
626
- title_col <- length(sizes $ widths ) + 1
627
- }
628
- )
610
+ if (sizes $ has_title ) {
611
+ switch (
612
+ params $ title.position ,
613
+ " top" = {
614
+ key_row <- key_row + 2
615
+ label_row <- label_row + 2
616
+ title_row <- 2
617
+ title_col <- seq_along(sizes $ widths ) + 1
618
+ },
619
+ " bottom" = {
620
+ title_row <- length(sizes $ heights ) + 1
621
+ title_col <- seq_along(sizes $ widths ) + 1
622
+ },
623
+ " left" = {
624
+ key_col <- key_col + 2
625
+ label_col <- label_col + 2
626
+ title_row <- seq_along(sizes $ heights ) + 1
627
+ title_col <- 2
628
+ },
629
+ " right" = {
630
+ title_row <- seq_along(sizes $ heights ) + 1
631
+ title_col <- length(sizes $ widths ) + 1
632
+ }
633
+ )
634
+ } else {
635
+ title_row <- NA
636
+ title_col <- NA
637
+ }
629
638
630
639
df <- cbind(df , key_row , key_col , label_row , label_col )
631
640
0 commit comments