diff --git a/R/plot_grid.R b/R/plot_grid.R index 2206573..19354f2 100644 --- a/R/plot_grid.R +++ b/R/plot_grid.R @@ -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) diff --git a/tests/figs/plot-grid/colwise-arranging.svg b/tests/figs/plot-grid/colwise-arranging.svg index 61d4554..666bfeb 100644 --- a/tests/figs/plot-grid/colwise-arranging.svg +++ b/tests/figs/plot-grid/colwise-arranging.svg @@ -57,22 +57,22 @@ - - + + - + - - + + - + diff --git a/tests/testthat/test_plot_grid.R b/tests/testthat/test_plot_grid.R index 3bab1ea..18d5546 100644 --- a/tests/testthat/test_plot_grid.R +++ b/tests/testthat/test_plot_grid.R @@ -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 + ) })