Skip to content

Commit 7e156d0

Browse files
committed
fix inside legend justification
1 parent 790fb2e commit 7e156d0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

R/guides-.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,21 +584,25 @@ Guides <- ggproto(
584584
stretch_x <- any(unlist(lapply(widths, unitType)) == "null")
585585
stretch_y <- any(unlist(lapply(heights, unitType)) == "null")
586586

587-
# Global justification of the complete legend box
588-
global_just <- paste0("legend.justification.", position)
589-
global_just <- valid.just(calc_element(global_just, theme))
590587
if (startsWith(position, "inside")) {
588+
# Global justification of the complete legend box
589+
global_just <- valid.just(calc_element(
590+
"legend.justification.inside", theme
591+
))
591592
# for inside guide legends, the position was attached in
592593
# each grob of the input grobs (which should share the same position)
593594
inside_position <- attr(.subset2(grobs, 1L), "inside_position") %||%
594-
# fallback to original method of ggplot2 <=3.3.5
595+
# fallback to original method of ggplot2 <=3.5.1
595596
.subset2(theme, "legend.position.inside") %||% global_just
596597
global_xjust <- global_just[1]
597598
global_yjust <- global_just[2]
598599
x <- inside_position[1]
599600
y <- inside_position[2]
600601
global_margin <- margin()
601602
} else {
603+
# Global justification of the complete legend box
604+
global_just <- paste0("legend.justification.", position)
605+
global_just <- valid.just(calc_element(global_just, theme))
602606
x <- global_xjust <- global_just[1]
603607
y <- global_yjust <- global_just[2]
604608
# Legends to the side of the plot need a margin for justification

0 commit comments

Comments
 (0)