Skip to content

Commit

Permalink
Fix #350 absolute tags are now correctly added to free plots
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Aug 26, 2024
1 parent c38a14e commit 03197c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 18 additions & 2 deletions R/plot_patchwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 03197c7

Please sign in to comment.