From 3350bcde5f665bae9c1dff10129e030ce0a25da8 Mon Sep 17 00:00:00 2001 From: nfrerebeau Date: Mon, 26 Aug 2024 14:47:43 +0200 Subject: [PATCH] Allow proportional sizing of faceted barplot --- R/barplot.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/barplot.R b/R/barplot.R index 8cc17cf..37e519e 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -48,11 +48,17 @@ barplot.CompositionMatrix <- function(height, ..., groups = get_groups(height), ## Save and restore old_par <- graphics::par( mar = if (horiz) c(0, 5.1, 0, 1) else c(5.1, 0, 0, 1), - oma = if (horiz) c(6, 0, 5, 0) else c(0, 6, 5, 0), - mfcol = if (horiz) c(n, 1) else c(1, n) + oma = if (horiz) c(6, 0, 5, 0) else c(0, 6, 5, 0) ) on.exit(graphics::par(old_par)) + ## Plot layout + mat <- matrix(data = seq_len(n), nrow = ifelse(horiz, n, 1)) + mat_prop <- vapply(X = z, FUN = nrow, FUN.VALUE = integer(1)) + mat_widths <- if (horiz) rep.int(1, nrow(mat)) else mat_prop + mat_heights <- if (horiz) mat_prop else rep.int(1, nrow(mat)) + graphics::layout(mat, widths = mat_widths, heights = mat_heights) + for (i in seq_len(n)) { graphics::barplot(height = t(z[[i]]), horiz = horiz, axes = FALSE, main = NULL, sub = NULL, xlab = NULL, ylab = NULL,