Skip to content

Commit 3e35c7a

Browse files
authored
Fix strip labels with expressions in it (#3780)
1 parent 5bc667e commit 3e35c7a

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

R/labeller.r

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -499,33 +499,39 @@ build_strip <- function(label_df, labeller, theme, horizontal) {
499499
# Create matrix of labels
500500
labels <- lapply(labeller(label_df), cbind)
501501
labels <- do.call("cbind", labels)
502+
ncol <- ncol(labels)
503+
nrow <- nrow(labels)
502504

503505
if (horizontal) {
504-
grobs_top <- apply(labels, c(1, 2), element_render, theme = theme,
505-
element = "strip.text.x.top", margin_x = TRUE,
506-
margin_y = TRUE)
507-
grobs_top <- assemble_strips(grobs_top, theme, horizontal, clip = "on")
506+
grobs_top <- lapply(labels, element_render, theme = theme,
507+
element = "strip.text.x.top", margin_x = TRUE,
508+
margin_y = TRUE)
509+
grobs_top <- assemble_strips(matrix(grobs_top, ncol = ncol, nrow = nrow),
510+
theme, horizontal, clip = "on")
508511

509-
grobs_bottom <- apply(labels, c(1, 2), element_render, theme = theme,
510-
element = "strip.text.x.bottom", margin_x = TRUE,
511-
margin_y = TRUE)
512-
grobs_bottom <- assemble_strips(grobs_bottom, theme, horizontal, clip = "on")
512+
grobs_bottom <- lapply(labels, element_render, theme = theme,
513+
element = "strip.text.x.bottom", margin_x = TRUE,
514+
margin_y = TRUE)
515+
grobs_bottom <- assemble_strips(matrix(grobs_bottom, ncol = ncol, nrow = nrow),
516+
theme, horizontal, clip = "on")
513517

514518
list(
515519
top = grobs_top,
516520
bottom = grobs_bottom
517521
)
518522
} else {
519-
grobs_left <- apply(labels, c(1, 2), element_render, theme = theme,
520-
element = "strip.text.y.left", margin_x = TRUE,
521-
margin_y = TRUE)
522-
grobs_left <- assemble_strips(grobs_left, theme, horizontal, clip = "on")
523-
524-
grobs_right <- apply(labels[, rev(seq_len(ncol(labels))), drop = FALSE],
525-
c(1, 2), element_render, theme = theme,
526-
element = "strip.text.y.right", margin_x = TRUE,
523+
grobs_left <- lapply(labels, element_render, theme = theme,
524+
element = "strip.text.y.left", margin_x = TRUE,
527525
margin_y = TRUE)
528-
grobs_right <- assemble_strips(grobs_right, theme, horizontal, clip = "on")
526+
grobs_left <- assemble_strips(matrix(grobs_left, ncol = ncol, nrow = nrow),
527+
theme, horizontal, clip = "on")
528+
529+
grobs_right <- lapply(labels[, rev(seq_len(ncol(labels))), drop = FALSE],
530+
element_render, theme = theme,
531+
element = "strip.text.y.right", margin_x = TRUE,
532+
margin_y = TRUE)
533+
grobs_right <- assemble_strips(matrix(grobs_right, ncol = ncol, nrow = nrow),
534+
theme, horizontal, clip = "on")
529535

530536
list(
531537
left = grobs_left,

0 commit comments

Comments
 (0)