Skip to content

Commit b2dfefe

Browse files
committed
fix code and add tests
1 parent 76443df commit b2dfefe

File tree

4 files changed

+187
-1
lines changed

4 files changed

+187
-1
lines changed

R/plot_grid.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ plot_grid <- function(..., plotlist = NULL, align = c("none", "h", "v", "hv"),
178178
if (is.null(rows)) rows <- ceiling(num_plots/cols)
179179

180180
# if the user wants to layout the plots by column, we use the calculated rows to reorder plots and labels
181-
if (!isTRUE(byrow))
181+
if (!isTRUE(byrow)){
182182
plots <- plots[c(t(matrix(c(1:num_plots, rep(NA, (rows * cols) - num_plots)), nrow = rows, byrow = FALSE)))]
183183
labels <- labels[c(t(matrix(c(1:num_plots, rep(NA, (rows * cols) - num_plots)), nrow = rows, byrow = FALSE)))]
184+
}
184185

185186
# Align the plots (if specified)
186187
grobs <- align_plots(plotlist = plots, align = align, axis = axis, greedy = greedy)
+85
Loading
+85
Loading

tests/testthat/test_plot_grid.R

+15
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,18 @@ test_that("alignment", {
9898
plot_grid(p1, p2, ncol = 1, align = 'v', axis = "rl") + theme_map()
9999
)
100100
})
101+
102+
103+
104+
test_that("labels reorder by byrow", {
105+
106+
p_list <- lapply(1:3, \(x) ggplot())
107+
108+
expect_doppelganger("byrow is TRUE",
109+
plot_grid(plotlist = p_list, ncol = 2, labels = 1:3, byrow = TRUE)
110+
)
111+
112+
expect_doppelganger("byrow is FALSE",
113+
plot_grid(plotlist = p_list, ncol = 2, labels = 1:3, byrow = FALSE)
114+
)
115+
})

0 commit comments

Comments
 (0)