Skip to content

Commit

Permalink
matrix issues when num_plots < row * col
Browse files Browse the repository at this point in the history
- Matrix normally pads via recycling.
- Pad matrix with NAs instead.
- Update visual test to be more specific to when `num_plots < row * col`.
  • Loading branch information
BrianLang committed Aug 19, 2020
1 parent d73f925 commit f764845
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion R/plot_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ plot_grid <- function(..., plotlist = NULL, align = c("none", "h", "v", "hv"),
if (is.null(rows)) rows <- ceiling(num_plots/cols)

# if the user wants to layout the plots by column, we use the calculated rows to reorder plots
if (!byrow) plots <- plots[c(t(matrix(1:num_plots, nrow = rows, byrow = byrow)))]
if (!byrow) plots <- plots[c(t(matrix(c(1:num_plots, rep(NA, (rows * cols) - num_plots)), nrow = rows, byrow = byrow)))]

# Align the plots (if specified)
grobs <- align_plots(plotlist = plots, align = align, axis = axis, greedy = greedy)
Expand Down
12 changes: 6 additions & 6 deletions tests/figs/plot-grid/colwise-arranging.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/testthat/test_plot_grid.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test_that("basic plot arranging works", {
)

expect_doppelganger("colwise arranging",
plot_grid(p1, NULL, p2, NULL, p3, NULL, byrow = FALSE) + theme_map()
) # add theme_map() for plot title
plot_grid(p1, NULL, p2, p3, NULL, byrow = FALSE) + theme_map() # add theme_map() for plot title
)
})


Expand Down

0 comments on commit f764845

Please sign in to comment.