diff --git a/NEWS.md b/NEWS.md index b037794..1873110 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,8 @@ * Empty patches no longer breaks up axis title collection (#375) * `wrap_ggplot_grob()` now respects auto-tagging (#363) * Fix a bug where guide collecting would prevent proper axes collecting (#359) +* Fix a bug in `free()` where tags placed on top of the plot region would become + missing (#350) # patchwork 1.2.0 diff --git a/R/plot_patchwork.R b/R/plot_patchwork.R index 7499337..cd08d8b 100644 --- a/R/plot_patchwork.R +++ b/R/plot_patchwork.R @@ -339,9 +339,25 @@ plot_table.free_plot <- function(x, guides) { ) } - gt <- gt[seq_len(nrow(gt) - 4) + 2, seq_len(ncol(gt) - 4) + 2] - table <- gtable_add_grob(table, list(gt), 3, 3, TABLE_ROWS - 2, + gt_central <- gt[seq_len(nrow(gt) - 4) + 2, seq_len(ncol(gt) - 4) + 2] + table <- gtable_add_grob(table, list(gt_central), 3, 3, TABLE_ROWS - 2, TABLE_COLS - 2, clip = 'on', name = 'free_plot') + + # Add tag if it was free floating and removed during the above indexing + if (!is_zero(tag) && !is.character(tag_pos) && !"tag" %in% gt_central$layout$name) { + tag_idx <- which(gt$layout$name == "tag") + table <- gtable_add_grob( + table, + tag, + name = "tag", + t = gt$layout$t[tag_idx], + l = gt$layout$l[tag_idx], + b = gt$layout$b[tag_idx], + r = gt$layout$r[tag_idx], + z <- max(table$layout$z) + 1, + clip = "off" + ) + } table$collected_guides <- collected_guides table }