Skip to content

Commit c98360e

Browse files
committed
apply key justification
1 parent 3fce5e7 commit c98360e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

R/guide-legend.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ GuideLegend <- ggproto(
174174
key = "legend.key",
175175
key_height = "legend.key.height",
176176
key_width = "legend.key.width",
177+
key_just = "legend.key.justification",
177178
text = "legend.text",
178179
theme.title = "legend.title",
179180
spacing_x = "legend.key.spacing.x",
@@ -373,6 +374,9 @@ GuideLegend <- ggproto(
373374
elements$key <-
374375
ggname("legend.key", element_grob(elements$key))
375376
}
377+
if (!is.null(elements$key_just)) {
378+
elements$key_just <- valid.just(elements$key_just)
379+
}
376380

377381
elements$text <-
378382
label_angle_heuristic(elements$text, elements$text_position, params$angle)
@@ -387,6 +391,7 @@ GuideLegend <- ggproto(
387391
build_decor = function(decor, grobs, elements, params) {
388392

389393
key_size <- c(elements$width_cm, elements$height_cm)
394+
just <- elements$key_just
390395
idx <- seq_len(params$n_breaks)
391396

392397
key_glyphs <- lapply(idx, function(i) {
@@ -404,7 +409,15 @@ GuideLegend <- ggproto(
404409
height <- vapply(glyph, get_attr, which = "height", default = 0, numeric(1))
405410
height <- max(height, 0, key_size[2], na.rm = TRUE)
406411

407-
grob <- gTree(children = inject(gList(elements$key, !!!glyph)))
412+
vp <- NULL
413+
if (!is.null(just)) {
414+
vp <- viewport(
415+
x = just[1], y = just[2], just = just,
416+
width = unit(width, "cm"), height = unit(height, "cm")
417+
)
418+
}
419+
420+
grob <- gTree(children = inject(gList(elements$key, !!!glyph)), vp = vp)
408421
attr(grob, "width") <- width
409422
attr(grob, "height") <- height
410423
grob

0 commit comments

Comments
 (0)