Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/plot_multipage.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ggplot_build.fixed_dim_ggplot <- function(plot, ...) {
ggplot_gtable.fixed_dim_build <- function(data) {
dim <- data$plot$fixed_dimensions
table <- NextMethod()
table <- add_strips(table)
table <- add_strips(table, data$plot$theme)
table <- add_guides(table, FALSE)
panel_pos <- find_panel(table)
table$widths[seq_len(panel_pos$l - 1)] <- unit(dim$l, 'mm')
Expand Down
18 changes: 12 additions & 6 deletions R/plot_patchwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,10 @@ plot_table <- function(x, guides) {
#' @importFrom ggplot2 ggplotGrob
#' @export
plot_table.ggplot <- function(x, guides) {
gt <- ggplotGrob(x)
gt <- add_strips(gt)
data <- ggplot_build(x)
gt <- ggplot_gtable(data)
# use the completed theme when adding strips
gt <- add_strips(gt, data$plot$theme)
add_guides(gt, guides == 'collect')
}
#' @export
Expand Down Expand Up @@ -939,10 +941,10 @@ set_border_sizes <- function(gt, l = NULL, r = NULL, t = NULL, b = NULL) {
#' @importFrom gtable gtable_add_rows gtable_add_cols
#' @importFrom grid unit
#' @importFrom ggplot2 find_panel
add_strips <- function(gt) {
add_strips <- function(gt, theme = NULL) {
panel_loc <- find_panel(gt)
strip_pos <- switch(
find_strip_pos(gt),
find_strip_pos(gt, theme),
inside = 0,
outside = 2
)
Expand Down Expand Up @@ -1059,7 +1061,7 @@ add_guides <- function(gt, collect = FALSE) {
}
gt
}
find_strip_pos <- function(gt) {
find_strip_pos <- function(gt, theme) {
panel_loc <- find_panel(gt)
ind <- grep('strip-t', gt$layout$name)
if (length(ind) != 0 && panel_loc$t - min(gt$layout$t[ind]) != 1) {
Expand All @@ -1077,7 +1079,11 @@ find_strip_pos <- function(gt) {
if (length(ind) != 0 && panel_loc$l - min(gt$layout$l[ind]) != 1) {
return('outside')
}
'inside'
if (is.null(theme)) {
'inside'
} else {
calc_element("strip.placement", theme) %||% "inside"
}
}

set_panel_dimensions <- function(gt, panels, widths, heights, fixed_asp, design) {
Expand Down
10 changes: 8 additions & 2 deletions R/wrap_ggplot_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ wrap_ggplot_grob <- function(x) {
attr(patch, 'table') <- x
patch
}

#' @importFrom ggplot2 ggplot_build ggplot_gtable
#' @importFrom gtable gtable_add_grob
#' @export
patchGrob.table_patch <- function(x, guides = 'auto') {
data <- ggplot_build(x)
gt <- attr(x, 'table')
gt <- add_strips(gt)
# use the completed theme when adding strips
gt <- add_strips(gt, data$plot$theme)
gt <- add_guides(gt, guides == 'collect')
if ("tag" %in% names(x$labels)) {
plot <- add_guides(add_strips(ggplotGrob(x)))
# use the completed theme when adding strips
plot <- add_guides(add_strips(ggplot_gtable(data), data$plot$theme))
tag_idx <- which(plot$layout$name == "tag")
gt <- gtable_add_grob(
gt,
Expand Down
Loading