diff --git a/R/facet-grid-.r b/R/facet-grid-.r index bc5e2b016e..449aeee532 100644 --- a/R/facet-grid-.r +++ b/R/facet-grid-.r @@ -311,7 +311,7 @@ FacetGrid <- ggproto("FacetGrid", Facet, } panel_table <- gtable_matrix("layout", panel_table, - panel_widths, panel_heights, respect = respect) + panel_widths, panel_heights, respect = respect, clip = "on") panel_table$layout$name <- paste0('panel-', rep(seq_len(ncol), nrow), '-', rep(seq_len(nrow), each = ncol)) panel_table <- gtable_add_col_space(panel_table, @@ -327,10 +327,10 @@ FacetGrid <- ggproto("FacetGrid", Facet, panel_pos_col <- panel_cols(panel_table) panel_pos_rows <- panel_rows(panel_table) - panel_table <- gtable_add_grob(panel_table, axes$x$top, 1, panel_pos_col$l, clip = "off", name = paste0("axis-t-", seq_along(axes$x$top))) - panel_table <- gtable_add_grob(panel_table, axes$x$bottom, -1, panel_pos_col$l, clip = "off", name = paste0("axis-b-", seq_along(axes$x$bottom))) - panel_table <- gtable_add_grob(panel_table, axes$y$left, panel_pos_rows$t, 1, clip = "off", name = paste0("axis-l-", seq_along(axes$y$left))) - panel_table <- gtable_add_grob(panel_table, axes$y$right, panel_pos_rows$t, -1, clip = "off", name = paste0("axis-r-", seq_along(axes$y$right))) + panel_table <- gtable_add_grob(panel_table, axes$x$top, 1, panel_pos_col$l, clip = "off", name = paste0("axis-t-", seq_along(axes$x$top)), z = 3) + panel_table <- gtable_add_grob(panel_table, axes$x$bottom, -1, panel_pos_col$l, clip = "off", name = paste0("axis-b-", seq_along(axes$x$bottom)), z = 3) + panel_table <- gtable_add_grob(panel_table, axes$y$left, panel_pos_rows$t, 1, clip = "off", name = paste0("axis-l-", seq_along(axes$y$left)), z = 3) + panel_table <- gtable_add_grob(panel_table, axes$y$right, panel_pos_rows$t, -1, clip = "off", name = paste0("axis-r-", seq_along(axes$y$right)), z= 3) # Add strips switch_x <- !is.null(params$switch) && params$switch %in% c("both", "x") @@ -343,22 +343,22 @@ FacetGrid <- ggproto("FacetGrid", Facet, if (!is.null(strips$x$bottom)) { if (inside_x) { panel_table <- gtable_add_rows(panel_table, max_height(strips$x$bottom), -2) - panel_table <- gtable_add_grob(panel_table, strips$x$bottom, -2, panel_pos_col$l, clip = "off", name = paste0("strip-b-", seq_along(strips$x$bottom))) + 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) } else { panel_table <- gtable_add_rows(panel_table, strip_padding, -1) panel_table <- gtable_add_rows(panel_table, max_height(strips$x$bottom), -1) - panel_table <- gtable_add_grob(panel_table, strips$x$bottom, -1, panel_pos_col$l, clip = "off", name = paste0("strip-b-", seq_along(strips$x$bottom))) + 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) } } } else { if (!is.null(strips$x$top)) { if (inside_x) { panel_table <- gtable_add_rows(panel_table, max_height(strips$x$top), 1) - panel_table <- gtable_add_grob(panel_table, strips$x$top, 2, panel_pos_col$l, clip = "off", name = paste0("strip-t-", seq_along(strips$x$top))) + 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) } else { panel_table <- gtable_add_rows(panel_table, strip_padding, 0) panel_table <- gtable_add_rows(panel_table, max_height(strips$x$top), 0) - panel_table <- gtable_add_grob(panel_table, strips$x$top, 1, panel_pos_col$l, clip = "off", name = paste0("strip-t-", seq_along(strips$x$top))) + 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) } } } @@ -367,22 +367,22 @@ FacetGrid <- ggproto("FacetGrid", Facet, if (!is.null(strips$y$left)) { if (inside_y) { panel_table <- gtable_add_cols(panel_table, max_width(strips$y$left), 1) - panel_table <- gtable_add_grob(panel_table, strips$y$left, panel_pos_rows$t, 2, clip = "off", name = paste0("strip-l-", seq_along(strips$y$left))) + 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) } else { panel_table <- gtable_add_cols(panel_table, strip_padding, 0) panel_table <- gtable_add_cols(panel_table, max_width(strips$y$left), 0) - panel_table <- gtable_add_grob(panel_table, strips$y$left, panel_pos_rows$t, 1, clip = "off", name = paste0("strip-l-", seq_along(strips$y$left))) + 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) } } } else { if (!is.null(strips$y$right)) { if (inside_y) { panel_table <- gtable_add_cols(panel_table, max_width(strips$y$right), -2) - panel_table <- gtable_add_grob(panel_table, strips$y$right, panel_pos_rows$t, -2, clip = "off", name = paste0("strip-r-", seq_along(strips$y$right))) + 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) } else { panel_table <- gtable_add_cols(panel_table, strip_padding, -1) panel_table <- gtable_add_cols(panel_table, max_width(strips$y$right), -1) - panel_table <- gtable_add_grob(panel_table, strips$y$right, panel_pos_rows$t, -1, clip = "off", name = paste0("strip-r-", seq_along(strips$y$right))) + 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) } } } diff --git a/R/facet-wrap.r b/R/facet-wrap.r index a5316a66a3..39163fc124 100644 --- a/R/facet-wrap.r +++ b/R/facet-wrap.r @@ -231,7 +231,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, empties <- apply(panel_table, c(1,2), function(x) is.zero(x[[1]])) panel_table <- gtable_matrix("layout", panel_table, widths = unit(rep(1, ncol), "null"), - heights = unit(rep(aspect_ratio, nrow), "null"), respect = respect) + heights = unit(rep(aspect_ratio, nrow), "null"), respect = respect, clip = "on") panel_table$layout$name <- paste0('panel-', rep(seq_len(ncol), nrow), '-', rep(seq_len(nrow), each = ncol)) panel_table <- gtable_add_col_space(panel_table, @@ -285,10 +285,10 @@ FacetWrap <- ggproto("FacetWrap", Facet, axis_mat_y_right[col_pos] <- col_axes } } - panel_table <- weave_tables_row(panel_table, axis_mat_x_top, -1, axis_height_top, "axis-t") - panel_table <- weave_tables_row(panel_table, axis_mat_x_bottom, 0, axis_height_bottom, "axis-b") - panel_table <- weave_tables_col(panel_table, axis_mat_y_left, -1, axis_width_left, "axis-l") - panel_table <- weave_tables_col(panel_table, axis_mat_y_right, 0, axis_width_right, "axis-r") + panel_table <- weave_tables_row(panel_table, axis_mat_x_top, -1, axis_height_top, "axis-t", 3) + panel_table <- weave_tables_row(panel_table, axis_mat_x_bottom, 0, axis_height_bottom, "axis-b", 3) + panel_table <- weave_tables_col(panel_table, axis_mat_y_left, -1, axis_width_left, "axis-l", 3) + panel_table <- weave_tables_col(panel_table, axis_mat_y_right, 0, axis_width_right, "axis-r", 3) strip_padding <- convertUnit(theme$strip.switch.pad.wrap, "cm") strip_name <- paste0("strip-", substr(params$strip.position, 1, 1)) @@ -304,7 +304,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, strip_pad <- axis_height_bottom } strip_height <- unit(apply(strip_mat, 1, max_height), "cm") - panel_table <- weave_tables_row(panel_table, strip_mat, placement, strip_height, strip_name) + panel_table <- weave_tables_row(panel_table, strip_mat, placement, strip_height, strip_name, 2, "on") if (!inside) { strip_pad[unclass(strip_pad) != 0] <- strip_padding panel_table <- weave_tables_row(panel_table, row_shift = placement, row_height = strip_pad) @@ -320,7 +320,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, } strip_pad[unclass(strip_pad) != 0] <- strip_padding strip_width <- unit(apply(strip_mat, 2, max_width), "cm") - panel_table <- weave_tables_col(panel_table, strip_mat, placement, strip_width, strip_name) + panel_table <- weave_tables_col(panel_table, strip_mat, placement, strip_width, strip_name, 2, "on") if (!inside) { strip_pad[unclass(strip_pad) != 0] <- strip_padding panel_table <- weave_tables_col(panel_table, col_shift = placement, col_width = strip_pad) @@ -414,26 +414,26 @@ convertInd <- function(row, col, nrow) { (col - 1) * nrow + row } -weave_tables_col <- function(table, table2, col_shift, col_width, name) { +weave_tables_col <- function(table, table2, col_shift, col_width, name, z = 1, clip = "off") { panel_col <- panel_cols(table)$l panel_row <- panel_rows(table)$t for (i in rev(seq_along(panel_col))) { col_ind <- panel_col[i] + col_shift table <- gtable_add_cols(table, col_width[i], pos = col_ind) if (!missing(table2)) { - table <- gtable_add_grob(table, table2[, i], t = panel_row, l = col_ind + 1, clip = 'off', name = paste0(name, '-', seq_along(panel_row), '-', i)) + table <- gtable_add_grob(table, table2[, i], t = panel_row, l = col_ind + 1, clip = clip, name = paste0(name, "-", seq_along(panel_row), "-", i), z = z) } } table } -weave_tables_row <- function(table, table2, row_shift, row_height, name) { +weave_tables_row <- function(table, table2, row_shift, row_height, name, z = 1, clip = "off") { panel_col <- panel_cols(table)$l panel_row <- panel_rows(table)$t for (i in rev(seq_along(panel_row))) { row_ind <- panel_row[i] + row_shift table <- gtable_add_rows(table, row_height[i], pos = row_ind) if (!missing(table2)) { - table <- gtable_add_grob(table, table2[i, ], t = row_ind + 1, l = panel_col, clip = 'off', name = paste0(name, '-', seq_along(panel_col), '-', i)) + table <- gtable_add_grob(table, table2[i, ], t = row_ind + 1, l = panel_col, clip = clip, name = paste0(name, "-", seq_along(panel_col), "-", i), z = z) } } table diff --git a/R/labeller.r b/R/labeller.r index d8aa2efc1a..aeffeba017 100644 --- a/R/labeller.r +++ b/R/labeller.r @@ -493,7 +493,7 @@ build_strip <- function(label_df, labeller, theme, horizontal) { horizontal = horizontal) heights <- unit(apply(grobs, 2, max_height), "cm") grobs <- apply(grobs, 1, function(strips) { - gtable_matrix("strip", matrix(strips, ncol = 1), unit(1, "null"), heights, clip = "off") + gtable_matrix("strip", matrix(strips, ncol = 1), unit(1, "null"), heights, clip = "on") }) list( top = grobs, @@ -505,7 +505,7 @@ build_strip <- function(label_df, labeller, theme, horizontal) { grobs_right <- grobs_right[, rev(seq_len(ncol(grobs_right))), drop = FALSE] widths <- unit(apply(grobs_right, 2, max_width), "cm") grobs_right <- apply(grobs_right, 1, function(strips) { - gtable_matrix("strip", matrix(strips, nrow = 1), widths, unit(1, "null"), clip = "off") + gtable_matrix("strip", matrix(strips, nrow = 1), widths, unit(1, "null"), clip = "on") }) theme$strip.text.y$angle <- adjust_angle(theme$strip.text.y$angle) grobs_left <- apply(labels, c(1, 2), ggstrip, theme = theme,