Skip to content

Commit 9c15f81

Browse files
authored
adhere to strip placement even if the axis is empty (#5630)
1 parent 0ee63c3 commit 9c15f81

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

R/facet-grid-.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,22 +443,26 @@ FacetGrid <- ggproto("FacetGrid", Facet,
443443
panel_pos_col <- panel_cols(panel_table)
444444
if (switch_x) {
445445
if (!is.null(strips$x$bottom)) {
446-
if (inside_x || all(vapply(axes$x$bottom, is.zero, logical(1)))) {
446+
if (inside_x) {
447447
panel_table <- gtable_add_rows(panel_table, max_height(strips$x$bottom), -2)
448448
panel_table <- gtable_add_grob(panel_table, strips$x$bottom, -2, panel_pos_col$l, clip = "on", name = paste0("strip-b-", seq_along(strips$x$bottom)), z = 2)
449449
} else {
450-
panel_table <- gtable_add_rows(panel_table, strip_padding, -1)
450+
if (!all(vapply(axes$x$bottom, is.zero, logical(1)))) {
451+
panel_table <- gtable_add_rows(panel_table, strip_padding, -1)
452+
}
451453
panel_table <- gtable_add_rows(panel_table, max_height(strips$x$bottom), -1)
452454
panel_table <- gtable_add_grob(panel_table, strips$x$bottom, -1, panel_pos_col$l, clip = "on", name = paste0("strip-b-", seq_along(strips$x$bottom)), z = 2)
453455
}
454456
}
455457
} else {
456458
if (!is.null(strips$x$top)) {
457-
if (inside_x || all(vapply(axes$x$top, is.zero, logical(1)))) {
459+
if (inside_x) {
458460
panel_table <- gtable_add_rows(panel_table, max_height(strips$x$top), 1)
459461
panel_table <- gtable_add_grob(panel_table, strips$x$top, 2, panel_pos_col$l, clip = "on", name = paste0("strip-t-", seq_along(strips$x$top)), z = 2)
460462
} else {
461-
panel_table <- gtable_add_rows(panel_table, strip_padding, 0)
463+
if (!all(vapply(axes$x$top, is.zero, logical(1)))) {
464+
panel_table <- gtable_add_rows(panel_table, strip_padding, 0)
465+
}
462466
panel_table <- gtable_add_rows(panel_table, max_height(strips$x$top), 0)
463467
panel_table <- gtable_add_grob(panel_table, strips$x$top, 1, panel_pos_col$l, clip = "on", name = paste0("strip-t-", seq_along(strips$x$top)), z = 2)
464468
}
@@ -467,22 +471,26 @@ FacetGrid <- ggproto("FacetGrid", Facet,
467471
panel_pos_rows <- panel_rows(panel_table)
468472
if (switch_y) {
469473
if (!is.null(strips$y$left)) {
470-
if (inside_y || all(vapply(axes$y$left, is.zero, logical(1)))) {
474+
if (inside_y) {
471475
panel_table <- gtable_add_cols(panel_table, max_width(strips$y$left), 1)
472476
panel_table <- gtable_add_grob(panel_table, strips$y$left, panel_pos_rows$t, 2, clip = "on", name = paste0("strip-l-", seq_along(strips$y$left)), z = 2)
473477
} else {
474-
panel_table <- gtable_add_cols(panel_table, strip_padding, 0)
478+
if (!all(vapply(axes$y$left, is.zero, logical(1)))) {
479+
panel_table <- gtable_add_cols(panel_table, strip_padding, 0)
480+
}
475481
panel_table <- gtable_add_cols(panel_table, max_width(strips$y$left), 0)
476482
panel_table <- gtable_add_grob(panel_table, strips$y$left, panel_pos_rows$t, 1, clip = "on", name = paste0("strip-l-", seq_along(strips$y$left)), z = 2)
477483
}
478484
}
479485
} else {
480486
if (!is.null(strips$y$right)) {
481-
if (inside_y || all(vapply(axes$y$right, is.zero, logical(1)))) {
487+
if (inside_y) {
482488
panel_table <- gtable_add_cols(panel_table, max_width(strips$y$right), -2)
483489
panel_table <- gtable_add_grob(panel_table, strips$y$right, panel_pos_rows$t, -2, clip = "on", name = paste0("strip-r-", seq_along(strips$y$right)), z = 2)
484490
} else {
485-
panel_table <- gtable_add_cols(panel_table, strip_padding, -1)
491+
if (!all(vapply(axes$y$right, is.zero, logical(1)))) {
492+
panel_table <- gtable_add_cols(panel_table, strip_padding, -1)
493+
}
486494
panel_table <- gtable_add_cols(panel_table, max_width(strips$y$right), -1)
487495
panel_table <- gtable_add_grob(panel_table, strips$y$right, panel_pos_rows$t, -1, clip = "on", name = paste0("strip-r-", seq_along(strips$y$right)), z = 2)
488496
}

0 commit comments

Comments
 (0)