From 3f93cbd0b2521800ddfb5fca6633dbe3d5b0edea Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:41:47 +0200 Subject: [PATCH 1/3] Replace `theme$element` by `calc_element(element, theme)` --- R/facet-grid-.R | 13 +++++++------ R/facet-null.R | 2 +- R/facet-wrap.R | 15 ++++++++------- R/guide-bins.R | 5 +++-- R/guide-colorbar.R | 4 ++-- R/guide-legend.R | 8 ++++---- R/guides-.R | 30 ++++++++++++++--------------- R/layout.R | 2 +- R/plot-build.R | 34 +++++++++++++++++---------------- vignettes/extending-ggplot2.Rmd | 24 ++++------------------- 10 files changed, 63 insertions(+), 74 deletions(-) diff --git a/R/facet-grid-.R b/R/facet-grid-.R index 3fa73f98f3..9915e9ad30 100644 --- a/R/facet-grid-.R +++ b/R/facet-grid-.R @@ -319,7 +319,7 @@ FacetGrid <- ggproto("FacetGrid", Facet, attr(row_vars, "facet") <- "grid" strips <- render_strips(col_vars, row_vars, params$labeller, theme) - aspect_ratio <- theme$aspect.ratio + aspect_ratio <- calc_element("aspect.ratio", theme) if (!is.null(aspect_ratio) && (params$space_free$x || params$space_free$y)) { cli::cli_abort("Free scales cannot be mixed with a fixed aspect ratio") } @@ -362,9 +362,9 @@ FacetGrid <- ggproto("FacetGrid", Facet, panel_table$layout$name <- paste0('panel-', rep(seq_len(nrow), ncol), '-', rep(seq_len(ncol), each = nrow)) panel_table <- gtable_add_col_space(panel_table, - theme$panel.spacing.x %||% theme$panel.spacing) + calc_element("panel.spacing.x", theme)) panel_table <- gtable_add_row_space(panel_table, - theme$panel.spacing.y %||% theme$panel.spacing) + calc_element("panel.spacing.y", theme)) # Add axes panel_table <- gtable_add_rows(panel_table, max_height(axes$x$top), 0) @@ -382,9 +382,10 @@ FacetGrid <- ggproto("FacetGrid", Facet, # Add strips switch_x <- !is.null(params$switch) && params$switch %in% c("both", "x") switch_y <- !is.null(params$switch) && params$switch %in% c("both", "y") - inside_x <- (theme$strip.placement.x %||% theme$strip.placement %||% "inside") == "inside" - inside_y <- (theme$strip.placement.y %||% theme$strip.placement %||% "inside") == "inside" - strip_padding <- convertUnit(theme$strip.switch.pad.grid, "cm") + inside_x <- (calc_element("strip.placement.x", theme) %||% "inside") == "inside" + inside_y <- (calc_element("strip.placement.y", theme) %||% "inside") == "inside" + strip_padding <- calc_element("strip.switch.pad.grid", theme) + strip_padding <- convertUnit(strip_padding, "cm") panel_pos_col <- panel_cols(panel_table) if (switch_x) { if (!is.null(strips$x$bottom)) { diff --git a/R/facet-null.R b/R/facet-null.R index bc95141fde..51c32aaea3 100644 --- a/R/facet-null.R +++ b/R/facet-null.R @@ -44,7 +44,7 @@ FacetNull <- ggproto("FacetNull", Facet, range <- ranges[[1]] # Figure out aspect ratio - aspect_ratio <- theme$aspect.ratio %||% coord$aspect(range) + aspect_ratio <- calc_element("aspect.ratio", theme) %||% coord$aspect(range) if (is.null(aspect_ratio)) { aspect_ratio <- 1 respect <- FALSE diff --git a/R/facet-wrap.R b/R/facet-wrap.R index b7c19a05f3..441c3370c1 100644 --- a/R/facet-wrap.R +++ b/R/facet-wrap.R @@ -257,7 +257,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, # If user hasn't set aspect ratio, and we have fixed scales, then # ask the coordinate system if it wants to specify one - aspect_ratio <- theme$aspect.ratio + aspect_ratio <- calc_element("aspect.ratio", theme) if (is.null(aspect_ratio) && !params$free$x && !params$free$y) { aspect_ratio <- coord$aspect(ranges[[1]]) } @@ -279,9 +279,9 @@ FacetWrap <- ggproto("FacetWrap", Facet, 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, - theme$panel.spacing.x %||% theme$panel.spacing) + calc_element("panel.spacing.x", theme)) panel_table <- gtable_add_row_space(panel_table, - theme$panel.spacing.y %||% theme$panel.spacing) + calc_element("panel.spacing.y", theme)) # Add axes axis_mat_x_top <- empty_table @@ -320,7 +320,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, if (any(empties)) { row_ind <- row(empties) col_ind <- col(empties) - inside <- (theme$strip.placement %||% "inside") == "inside" + inside <- (calc_element("strip.placement", theme) %||% "inside") == "inside" empty_bottom <- apply(empties, 2, function(x) c(diff(x) == 1, FALSE)) if (any(empty_bottom)) { pos <- which(empty_bottom) @@ -403,12 +403,13 @@ FacetWrap <- ggproto("FacetWrap", Facet, 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_padding <- calc_element("strip.switch.pad.wrap", theme) + strip_padding <- convertUnit(strip_padding, "cm") strip_name <- paste0("strip-", substr(params$strip.position, 1, 1)) strip_mat <- empty_table strip_mat[panel_pos] <- unlist(unname(strips), recursive = FALSE)[[params$strip.position]] if (params$strip.position %in% c("top", "bottom")) { - inside_x <- (theme$strip.placement.x %||% theme$strip.placement %||% "inside") == "inside" + inside_x <- (calc_element("strip.placement.x", theme) %||% "inside") == "inside" if (params$strip.position == "top") { placement <- if (inside_x) -1 else -2 strip_pad <- axis_height_top @@ -423,7 +424,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, panel_table <- weave_tables_row(panel_table, row_shift = placement, row_height = strip_pad) } } else { - inside_y <- (theme$strip.placement.y %||% theme$strip.placement %||% "inside") == "inside" + inside_y <- (calc_element("strip.placement.y", theme) %||% "inside") == "inside" if (params$strip.position == "left") { placement <- if (inside_y) -1 else -2 strip_pad <- axis_width_left diff --git a/R/guide-bins.R b/R/guide-bins.R index bfdd9d0701..a0ac6d112b 100644 --- a/R/guide-bins.R +++ b/R/guide-bins.R @@ -334,8 +334,9 @@ GuideBins <- ggproto( }, override_elements = function(params, elements, theme) { - elements$ticks <- combine_elements(elements$ticks, theme$line) - elements$line <- combine_elements(elements$line, theme$line) + line <- calc_element("line", theme) + elements$ticks <- combine_elements(elements$ticks, line) + elements$line <- combine_elements(elements$line, line) GuideLegend$override_elements(params, elements, theme) }, diff --git a/R/guide-colorbar.R b/R/guide-colorbar.R index 65291f37cc..e42cbac1ee 100644 --- a/R/guide-colorbar.R +++ b/R/guide-colorbar.R @@ -410,8 +410,8 @@ GuideColourbar <- ggproto( } else { elements$key.height <- elements$key.height * 5 } - elements$ticks <- combine_elements(elements$ticks, theme$line) - elements$frame <- combine_elements(elements$frame, theme$rect) + elements$ticks <- combine_elements(elements$ticks, calc_element("line", theme)) + elements$frame <- combine_elements(elements$frame, calc_element("rect", theme)) GuideLegend$override_elements(params, elements, theme) }, diff --git a/R/guide-legend.R b/R/guide-legend.R index 0e6193aa24..9bc0da6052 100644 --- a/R/guide-legend.R +++ b/R/guide-legend.R @@ -414,11 +414,11 @@ GuideLegend <- ggproto( } # Breaking justification inheritance for intuition purposes. if (is.null(params$label.theme$hjust) && - is.null(theme$legend.text$hjust)) { + is.null(theme[["legend.text"]]$hjust)) { label$hjust <- NULL } if (is.null(params$label.theme$vjust) && - is.null(theme$legend.text$vjust)) { + is.null(theme[["legend.text"]]$vjust)) { label$vjust <- NULL } label$hjust <- params$label.hjust %||% elements$text.align %||% @@ -439,8 +439,8 @@ GuideLegend <- ggproto( elements$text$size %||% 11 gap <- unit(gap * 0.5, "pt") # Should maybe be elements$spacing.{x/y} instead of the theme's spacing? - elements$hgap <- width_cm( theme$legend.spacing.x %||% gap) - elements$vgap <- height_cm(theme$legend.spacing.y %||% gap) + elements$hgap <- width_cm( theme[["legend.spacing.x"]] %||% gap) + elements$vgap <- height_cm(theme[["legend.spacing.y"]] %||% gap) elements$padding <- convertUnit( elements$margin %||% margin(), "cm", valueOnly = TRUE diff --git a/R/guides-.R b/R/guides-.R index f8273d07e6..5f7130e017 100644 --- a/R/guides-.R +++ b/R/guides-.R @@ -252,14 +252,14 @@ Guides <- ggproto( return(no_guides) } - theme$legend.key.width <- theme$legend.key.width %||% theme$legend.key.size - theme$legend.key.height <- theme$legend.key.height %||% theme$legend.key.size + theme[["legend.key.width"]] <- calc_element("legend.key.width", theme) + theme[["legend.key.height"]] <- calc_element("legend.key.height", theme) default_direction <- if (position == "inside") "vertical" else position - theme$legend.box <- theme$legend.box %||% default_direction - theme$legend.direction <- theme$legend.direction %||% default_direction - theme$legend.box.just <- theme$legend.box.just %||% switch( + theme[["legend.box"]] <- calc_element("legend.box", theme) %||% default_direction + theme[["legend.direction"]] <- calc_element("legend.direction", theme) %||% default_direction + theme[["legend.box.just"]] <- calc_element("legend.box.just", theme) %||% switch( position, inside = c("center", "center"), vertical = c("left", "top"), @@ -272,7 +272,7 @@ Guides <- ggproto( return(no_guides) } guides <- self$setup(scales) - guides$train(scales, theme$legend.direction, labels) + guides$train(scales, calc_element("legend.direction", theme), labels) if (length(guides$guides) == 0) { return(no_guides) } @@ -461,9 +461,9 @@ Guides <- ggproto( # Combining multiple guides in a guide box assemble = function(grobs, theme) { # Set spacing - theme$legend.spacing <- theme$legend.spacing %||% unit(0.5, "lines") - theme$legend.spacing.y <- theme$legend.spacing.y %||% theme$legend.spacing - theme$legend.spacing.x <- theme$legend.spacing.x %||% theme$legend.spacing + theme[["legend.spacing"]] <- calc_element("legend.spacing", theme) %||% unit(0.5, "lines") + theme[["legend.spacing.y"]] <- calc_element("legend.spacing.y", theme) + theme[["legend.spacing.x"]] <- calc_element("legend.spacing.x", theme) # Measure guides widths <- lapply(grobs, function(g) sum(g$widths)) @@ -473,12 +473,12 @@ Guides <- ggproto( # Set the justification of each legend within the legend box # First value is xjust, second value is yjust - just <- valid.just(theme$legend.box.just) + just <- valid.just(calc_element("legend.box.just", theme)) xjust <- just[1] yjust <- just[2] # setting that is different for vertical and horizontal guide-boxes. - if (identical(theme$legend.box, "horizontal")) { + if (identical(calc_element("legend.box", theme), "horizontal")) { # Set justification for each legend for (i in seq_along(grobs)) { grobs[[i]] <- editGrob( @@ -493,7 +493,7 @@ Guides <- ggproto( widths = widths, height = max(heights)) # add space between the guide-boxes - guides <- gtable_add_col_space(guides, theme$legend.spacing.x) + guides <- gtable_add_col_space(guides, calc_element("legend.spacing.x", theme)) } else { # theme$legend.box == "vertical" # Set justification for each legend @@ -510,18 +510,18 @@ Guides <- ggproto( width = max(widths), heights = heights) # add space between the guide-boxes - guides <- gtable_add_row_space(guides, theme$legend.spacing.y) + guides <- gtable_add_row_space(guides, calc_element("legend.spacing.y", theme)) } # Add margins around the guide-boxes. - margin <- theme$legend.box.margin %||% margin() + margin <- calc_element("legend.box.margin", theme) %||% margin() guides <- gtable_add_cols(guides, margin[4], pos = 0) guides <- gtable_add_cols(guides, margin[2], pos = ncol(guides)) guides <- gtable_add_rows(guides, margin[1], pos = 0) guides <- gtable_add_rows(guides, margin[3], pos = nrow(guides)) # Add legend box background - background <- element_grob(theme$legend.box.background %||% element_blank()) + background <- element_render(theme, "legend.box.background") guides <- gtable_add_grob( guides, background, diff --git a/R/layout.R b/R/layout.R index 6e2124e8be..95d26bd3be 100644 --- a/R/layout.R +++ b/R/layout.R @@ -80,7 +80,7 @@ Layout <- ggproto("Layout", NULL, coord_fg <- self$coord$render_fg(self$panel_params[[i]], theme) coord_bg <- self$coord$render_bg(self$panel_params[[i]], theme) - if (isTRUE(theme$panel.ontop)) { + if (isTRUE(calc_element("panel.ontop", theme))) { panel <- c(panel, list(coord_bg), list(coord_fg)) } else { panel <- c(list(coord_bg), panel, list(coord_fg)) diff --git a/R/plot-build.R b/R/plot-build.R index 2c1695e350..9b732ce4e8 100644 --- a/R/plot-build.R +++ b/R/plot-build.R @@ -172,7 +172,7 @@ ggplot_gtable.ggplot_built <- function(data) { plot_table <- layout$render(geom_grobs, data, theme, plot$labels) # Legends - position <- theme$legend.position %||% "right" + position <- calc_element("legend.position", theme) %||% "right" if (length(position) == 2) { position <- "manual" } @@ -190,13 +190,14 @@ ggplot_gtable.ggplot_built <- function(data) { # Set the justification of the legend box # First value is xjust, second value is yjust - just <- valid.just(theme$legend.justification) + just <- valid.just(calc_element("legend.justification", theme)) xjust <- just[1] yjust <- just[2] if (position == "manual") { - xpos <- theme$legend.position[1] - ypos <- theme$legend.position[2] + pos <- calc_element("legend.position", theme) + xpos <- pos[1] + ypos <- pos[2] # x and y are specified via theme$legend.position (i.e., coords) legend_box <- editGrob( @@ -232,24 +233,24 @@ ggplot_gtable.ggplot_built <- function(data) { # for align-to-device, use this: # panel_dim <- summarise(plot_table$layout, t = min(t), r = max(r), b = max(b), l = min(l)) - theme$legend.box.spacing <- theme$legend.box.spacing %||% unit(0.2, 'cm') + legend.box.spacing <- calc_element("legend.box.spacing", theme) %||% unit(0.2, "cm") if (position == "left") { - plot_table <- gtable_add_cols(plot_table, theme$legend.box.spacing, pos = 0) + plot_table <- gtable_add_cols(plot_table, legend.box.spacing, pos = 0) plot_table <- gtable_add_cols(plot_table, legend_width, pos = 0) plot_table <- gtable_add_grob(plot_table, legend_box, clip = "off", t = panel_dim$t, b = panel_dim$b, l = 1, r = 1, name = "guide-box") } else if (position == "right") { - plot_table <- gtable_add_cols(plot_table, theme$legend.box.spacing, pos = -1) + plot_table <- gtable_add_cols(plot_table, legend.box.spacing, pos = -1) plot_table <- gtable_add_cols(plot_table, legend_width, pos = -1) plot_table <- gtable_add_grob(plot_table, legend_box, clip = "off", t = panel_dim$t, b = panel_dim$b, l = -1, r = -1, name = "guide-box") } else if (position == "bottom") { - plot_table <- gtable_add_rows(plot_table, theme$legend.box.spacing, pos = -1) + plot_table <- gtable_add_rows(plot_table, legend.box.spacing, pos = -1) plot_table <- gtable_add_rows(plot_table, legend_height, pos = -1) plot_table <- gtable_add_grob(plot_table, legend_box, clip = "off", t = -1, b = -1, l = panel_dim$l, r = panel_dim$r, name = "guide-box") } else if (position == "top") { - plot_table <- gtable_add_rows(plot_table, theme$legend.box.spacing, pos = 0) + plot_table <- gtable_add_rows(plot_table, legend.box.spacing, pos = 0) plot_table <- gtable_add_rows(plot_table, legend_height, pos = 0) plot_table <- gtable_add_grob(plot_table, legend_box, clip = "off", t = 1, b = 1, l = panel_dim$l, r = panel_dim$r, name = "guide-box") @@ -277,14 +278,14 @@ ggplot_gtable.ggplot_built <- function(data) { # "panel" means align to the panel(s) # "plot" means align to the entire plot (except margins and tag) title_pos <- arg_match0( - theme$plot.title.position %||% "panel", + calc_element("plot.title.position", theme) %||% "panel", c("panel", "plot"), arg_nm = "plot.title.position", error_call = expr(theme()) ) caption_pos <- arg_match0( - theme$plot.caption.position %||% "panel", + calc_element("plot.caption.position", theme) %||% "panel", values = c("panel", "plot"), arg_nm = "plot.caption.position", error_call = expr(theme()) @@ -321,12 +322,13 @@ ggplot_gtable.ggplot_built <- function(data) { plot_table <- table_add_tag(plot_table, plot$labels$tag, theme) # Margins - plot_table <- gtable_add_rows(plot_table, theme$plot.margin[1], pos = 0) - plot_table <- gtable_add_cols(plot_table, theme$plot.margin[2]) - plot_table <- gtable_add_rows(plot_table, theme$plot.margin[3]) - plot_table <- gtable_add_cols(plot_table, theme$plot.margin[4], pos = 0) + plot.margin <- calc_element("plot.margin", theme) + plot_table <- gtable_add_rows(plot_table, plot.margin[1], pos = 0) + plot_table <- gtable_add_cols(plot_table, plot.margin[2]) + plot_table <- gtable_add_rows(plot_table, plot.margin[3]) + plot_table <- gtable_add_cols(plot_table, plot.margin[4], pos = 0) - if (inherits(theme$plot.background, "element")) { + if (inherits(calc_element("plot.background", theme), "element")) { plot_table <- gtable_add_grob(plot_table, element_render(theme, "plot.background"), t = 1, l = 1, b = -1, r = -1, name = "background", z = -Inf) diff --git a/vignettes/extending-ggplot2.Rmd b/vignettes/extending-ggplot2.Rmd index 66a610babe..655645d1f1 100644 --- a/vignettes/extending-ggplot2.Rmd +++ b/vignettes/extending-ggplot2.Rmd @@ -724,21 +724,13 @@ render <- function(panels, layout, x_scales, y_scales, ranges, coord, data, panel_table <- gtable::gtable_matrix("layout", panels, widths = unit(c(1, 1), "null"), heights = unit(1, "null"), clip = "on") # Add spacing according to theme - panel_spacing <- if (is.null(theme$panel.spacing.x)) { - theme$panel.spacing - } else { - theme$panel.spacing.x - } + panel_spacing <- calc_element("panel.spacing.x", theme) panel_table <- gtable::gtable_add_col_space(panel_table, panel_spacing) } else { panels <- matrix(panels, ncol = 1) panel_table <- gtable::gtable_matrix("layout", panels, widths = unit(1, "null"), heights = unit(c(1, 1), "null"), clip = "on") - panel_spacing <- if (is.null(theme$panel.spacing.y)) { - theme$panel.spacing - } else { - theme$panel.spacing.y - } + panel_spacing <- calc_element("panel.spacing.y", theme) panel_table <- gtable::gtable_add_row_space(panel_table, panel_spacing) } # Name panel grobs so they can be found later @@ -909,21 +901,13 @@ FacetTrans <- ggproto("FacetTrans", Facet, panel_table <- gtable::gtable_matrix("layout", panels, widths = unit(c(1, 1), "null"), heights = unit(1, "null"), clip = "on") # Add spacing according to theme - panel_spacing <- if (is.null(theme$panel.spacing.x)) { - theme$panel.spacing - } else { - theme$panel.spacing.x - } + panel_spacing <- calc_element("panel.spacing.x", theme) panel_table <- gtable::gtable_add_col_space(panel_table, panel_spacing) } else { panels <- matrix(panels, ncol = 1) panel_table <- gtable::gtable_matrix("layout", panels, widths = unit(1, "null"), heights = unit(c(1, 1), "null"), clip = "on") - panel_spacing <- if (is.null(theme$panel.spacing.y)) { - theme$panel.spacing - } else { - theme$panel.spacing.y - } + panel_spacing <- calc_element("panel.spacing.y", theme) panel_table <- gtable::gtable_add_row_space(panel_table, panel_spacing) } # Name panel grobs so they can be found later From 3b2f6b71cd3f4ecb860441f0a2894f241aff9285 Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:41:59 +0200 Subject: [PATCH 2/3] Correct defaults --- R/theme-defaults.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/theme-defaults.R b/R/theme-defaults.R index 5c1018e85f..01737520df 100644 --- a/R/theme-defaults.R +++ b/R/theme-defaults.R @@ -481,6 +481,7 @@ theme_void <- function(base_size = 11, base_family = "", axis.ticks.length.y.left = NULL, axis.ticks.length.y.right = NULL, legend.box = NULL, + legend.box.background = element_blank(), legend.key.size = unit(1.2, "lines"), legend.position = "right", legend.text = element_text(size = rel(0.8)), @@ -491,7 +492,7 @@ theme_void <- function(base_size = 11, base_family = "", strip.switch.pad.wrap = unit(half_line / 2, "pt"), panel.ontop = FALSE, panel.spacing = unit(half_line, "pt"), - plot.margin = unit(c(0, 0, 0, 0), "lines"), + plot.margin = margin(unit = "lines"), plot.title = element_text( size = rel(1.2), hjust = 0, vjust = 1, From 741bc8578e1fea946f3c5ad461434c8308042ece Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:56:54 +0200 Subject: [PATCH 3/3] Fix indentation --- R/facet-grid-.R | 12 ++++++++---- R/facet-wrap.R | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/R/facet-grid-.R b/R/facet-grid-.R index 9915e9ad30..4dc15192d8 100644 --- a/R/facet-grid-.R +++ b/R/facet-grid-.R @@ -361,10 +361,14 @@ FacetGrid <- ggproto("FacetGrid", Facet, panel_widths, panel_heights, respect = respect, clip = coord$clip, z = matrix(1, ncol = ncol, nrow = nrow)) panel_table$layout$name <- paste0('panel-', rep(seq_len(nrow), ncol), '-', rep(seq_len(ncol), each = nrow)) - panel_table <- gtable_add_col_space(panel_table, - calc_element("panel.spacing.x", theme)) - panel_table <- gtable_add_row_space(panel_table, - calc_element("panel.spacing.y", theme)) + panel_table <- gtable_add_col_space( + panel_table, + calc_element("panel.spacing.x", theme) + ) + panel_table <- gtable_add_row_space( + panel_table, + calc_element("panel.spacing.y", theme) + ) # Add axes panel_table <- gtable_add_rows(panel_table, max_height(axes$x$top), 0) diff --git a/R/facet-wrap.R b/R/facet-wrap.R index 441c3370c1..24fd7ed6c5 100644 --- a/R/facet-wrap.R +++ b/R/facet-wrap.R @@ -278,10 +278,14 @@ FacetWrap <- ggproto("FacetWrap", Facet, heights = unit(rep(abs(aspect_ratio), nrow), "null"), respect = respect, clip = coord$clip, z = matrix(1, ncol = ncol, nrow = nrow)) 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, - calc_element("panel.spacing.x", theme)) - panel_table <- gtable_add_row_space(panel_table, - calc_element("panel.spacing.y", theme)) + panel_table <- gtable_add_col_space( + panel_table, + calc_element("panel.spacing.x", theme) + ) + panel_table <- gtable_add_row_space( + panel_table, + calc_element("panel.spacing.y", theme) + ) # Add axes axis_mat_x_top <- empty_table