From 862b22cd2075184fa8abb298e204f9c28cb70b0f Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Thu, 27 Dec 2018 12:48:20 +0900 Subject: [PATCH] Fix a bug about strip.placement in facet_wrap() --- R/facet-wrap.r | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/R/facet-wrap.r b/R/facet-wrap.r index 8b8a29b2ee..ac5b47becc 100644 --- a/R/facet-wrap.r +++ b/R/facet-wrap.r @@ -295,8 +295,9 @@ FacetWrap <- ggproto("FacetWrap", Facet, col_panels <- which(layout$ROW > first_row & layout$COL == first_col) col_pos <- convertInd(layout$ROW[col_panels], layout$COL[col_panels], nrow) col_axes <- axes$y$right[layout$SCALE_Y[col_panels]] + inside <- (theme$strip.placement %||% "inside") == "inside" if (params$strip.position == "bottom" && - theme$strip.placement != "inside" && + !inside && any(!vapply(row_axes, is.zero, logical(1))) && !params$free$x) { warning("Suppressing axis rendering when strip.position = 'bottom' and strip.placement == 'outside'", call. = FALSE) @@ -304,7 +305,7 @@ FacetWrap <- ggproto("FacetWrap", Facet, axis_mat_x_bottom[row_pos] <- row_axes } if (params$strip.position == "right" && - theme$strip.placement != "inside" && + !inside && any(!vapply(col_axes, is.zero, logical(1))) && !params$free$y) { warning("Suppressing axis rendering when strip.position = 'right' and strip.placement == 'outside'", call. = FALSE) @@ -322,33 +323,33 @@ FacetWrap <- ggproto("FacetWrap", Facet, 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 <- (theme$strip.placement.x %||% theme$strip.placement %||% "inside") == "inside" + inside_x <- (theme$strip.placement.x %||% theme$strip.placement %||% "inside") == "inside" if (params$strip.position == "top") { - placement <- if (inside) -1 else -2 + placement <- if (inside_x) -1 else -2 strip_pad <- axis_height_top } else { - placement <- if (inside) 0 else 1 + placement <- if (inside_x) 0 else 1 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, 2, coord$clip) - if (!inside) { + if (!inside_x) { strip_pad[unclass(strip_pad) != 0] <- strip_padding panel_table <- weave_tables_row(panel_table, row_shift = placement, row_height = strip_pad) } } else { - inside <- (theme$strip.placement.y %||% theme$strip.placement %||% "inside") == "inside" + inside_y <- (theme$strip.placement.y %||% theme$strip.placement %||% "inside") == "inside" if (params$strip.position == "left") { - placement <- if (inside) -1 else -2 + placement <- if (inside_y) -1 else -2 strip_pad <- axis_width_left } else { - placement <- if (inside) 0 else 1 + placement <- if (inside_y) 0 else 1 strip_pad <- axis_width_right } 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, 2, coord$clip) - if (!inside) { + if (!inside_y) { strip_pad[unclass(strip_pad) != 0] <- strip_padding panel_table <- weave_tables_col(panel_table, col_shift = placement, col_width = strip_pad) }