arrange_on_page: Arrange plots on a page

Description Usage Arguments Details Value Examples

Description

This helper can be used to arrange plots with layout on multiple pages. Unused positions on the grid are indexed with NA.

Usage

1
arrange_on_page(items = NULL, byrow = TRUE)

Arguments

items

A list of items to arrange.

byrow

Whether to fill rows or columns first per page.

Details

As a side-effect of calling this function, the layout of the current device is set to a matrix of nrow x ncol.

Value

An integer vector of indices that can be used to sort items so that they are neatly placed on a single page or multiple pages with nrow x ncol places. The index is filled with NA on the last page.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
op <- graphics::par(no.readonly = TRUE)  # reconstitute par(...) afterwards
par(mfcol = c(4, 2), mar = rep(0, 4))
graphics::layout.show(9)  # one single plot on page 2

plot_me <- function(n) {

  for (i in n) {
    plot.new()
    text(0.5, 0.5, i)
  }

}

plot_me(seq(1, 3))  # appended on same page

par(mfcol = c(4, 2), mar = rep(0, 4))  # starts new page, but not always "accessible"

plot_me(arrange_on_page(seq(1, 9), byrow = FALSE))
plot_me(LETTERS[arrange_on_page(seq(1, 2), byrow = TRUE)])

rm(plot_me)
par(op)

benjbuch/summerr documentation built on July 11, 2021, 9:40 a.m.