Skip to content

Commit

Permalink
Allow proportional sizing of faceted barplot
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Aug 26, 2024
1 parent cb00df5 commit 3350bcd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3350bcd

Please sign in to comment.