plot_band_page() creates n_bands copies of a plot_band() band and
arranges them, at their true printed size, in a grid on page — a thin
wrapper around page_layout() (the same layout function used for a grid
of cards), which handles sizing the grid to the band's true dimensions,
shrinking it to fit if n_bands is fewer than page holds, positioning
that grid via position, gutter spacing, margins, crop marks, and
pagination when n_bands doesn't fit on one page. The result can be
saved directly with ggplot2::ggsave().
Usage
plot_band_page(
paper,
orientation = c("horizontal", "vertical"),
n = NULL,
pt = 10,
x = NULL,
thickness = NULL,
overlap = NULL,
band_width = NULL,
fill = "white",
color = "black",
linewidth = 0.5,
glue_fill = "grey85",
fold_linetype = "dashed",
fold_linewidth = linewidth/2,
page = "letter",
page_orientation = NULL,
n_bands = 1,
ncol = NULL,
nrow = NULL,
byrow = FALSE,
gutter = NULL,
margin = NULL,
position = "center",
unit = "in",
marks = FALSE,
paginate = TRUE
)Arguments
- paper
Paper, page, or card name, or a data.frame with width and height columns (as returned by
get_page_size()ormake_page_size()), passed toas_page(). Sets the width and height of the stack of cards or paper the band wraps around.- orientation
Band orientation, either
"horizontal"or"vertical"."horizontal"wraps the band left-to-right, crossing the middle of the stack, so the band's panels use thewidthofpaperand the band's own height is set byband_width."vertical"wraps the band top-to-bottom instead, so the panels useheightand the band's own width is set byband_width. Default:"horizontal"- n, pt, x
Passed to
as_thickness()to calculate the thickness of the stack. Ignored ifthicknessis supplied.ptis also used to add a small ease allowance (the caliper of a single sheet or card) to the folded side segments of the band, since a flat band can't wrap tightly around a stack at its exact thickness. Ignored ifthicknessis supplied.- thickness
Optional. A
unitobject or number (in the units ofpaper) with the thickness of the stack, overridingn,pt, andx. If supplied, no ease allowance is added andthicknesssets the folded side segments of the band exactly. Default:NULL- overlap
Distance the band extends past the far edge of the stack, forming a segment that can be glued or taped closed. A
unitobject or a number (in the units ofpaper). Default:NULL, which uses 40% of thewidthofpaper(iforientationis"horizontal") or 40% of theheightofpaper(iforientationis"vertical") — i.e. 40% of whichever dimension ofpaperthe band wraps around.- band_width
Height of the band if
orientationis"horizontal", or width of the band iforientationis"vertical"— the dimension of the band perpendicular to the direction it wraps around the stack. Aunitobject or a number (in the units ofpaper). Default:NULL, which uses 40% of theheightofpaper(iforientationis"horizontal") or 40% of thewidthofpaper(iforientationis"vertical").- fill, color, linewidth
Fill, outline color, and outline linewidth for the band, Default:
"white","black", and0.5- glue_fill
Fill color used to distinguish the overlapping segment of the band set by
overlap, Default:"grey85"- fold_linetype, fold_linewidth
Linetype and linewidth for the lines marking where the band should be folded, Default:
"dashed"andlinewidth / 2- page
Paper name or a data.frame with width and height columns, passed to
page_layout(). Default:"letter"- page_orientation
Page orientation, passed to
page_layout()'sorientationparameter (kept as a separate parameter here to avoid a name clash with the band's ownorientation). Default:NULL, which usespageas supplied without reorienting it (unlikepage_layout()itself, which defaults to"landscape").- n_bands
Number of copies of the band to arrange on
page. Default:1- ncol, nrow
The dimensions of the grid to create. If both are
NULL, dims will be used or dims will be determined based on the plot dimensions.- byrow
Analogous to
byrowin matrix(). IfFALSEthe plots will be filled in in column-major order- gutter
Optional. Spacing to add between plots in the grid, as a single number (used for both row and column spacing), a length-2 numeric vector
c(row, col), or a named vector or list withrowandcolelements. Interpreted inunit. Implemented by adding half ofgutterto the interior-facing sides of each plot's ownplot.margin(so two adjacent plots each contribute half, summing to the full gutter between them) based on its row/column position in thencolxnrowgrid — this replaces each plot's existingplot.margin. Plots on the outer edge of the grid are not padded on their outward-facing side; usemarginfor space around the outside of the whole grid. Default:NULL(no extra spacing).gutterchanges the total size of the combined grid (adding(ncol - 1) * col_gutterand(nrow - 1) * row_gutter), whichmarksaccounts for automatically — the automaticncol/nrowcalculation frompage/dimsalso reserves room for it, so fewer plots may fit per page than withgutter = 0.- margin
Optional. A margin to add around the outside of the combined grid of plots, e.g. so the grid can be centered on a larger sheet of paper when saved with
ggplot2::ggsave(). Passed toget_margin()with unit. The margin pads the composed page rather than the individual plots inplots, and does not affect the number of rows and columns in the grid. Default:NULL, which computes a margin frompositionwhenever plot dimensions are known (supplied viadims, or auto-detected from the first plot) — seeposition. Setmarginexplicitly to override that (or to add a margin when dimensions aren't known, e.g.ncol/nrowsupplied withoutdims).marginitself always renders correctly regardless ofpage, because it is applied as a fixed absolute-unit margin around whatever canvas sizeggplot2::ggsave()is eventually called with.marks, below, is the one that depends onpagebeing set correctly — seemarks.- position
Where to place the bands on
pagewhenn_bandsdoesn't fill it completely. Passed topage_layout()'spositionparameter, but defaults to"center"here rather thanpage_layout()'s own"top-left"default.- unit
Unit used for
gutter, and formarginif margin is a bare numeric vector or list (ignored formarginif it is aunitclass object;gutterdoes not supportunitclass objects). Default:"in".- marks
If
TRUE, add crop marks in themarginarea showing where to cut the page into individual plots. Requiresmargin. Marks are placed assuming the grid of plots exactly fills the page after subtractingmargin, i.e. the same assumptionmarginitself relies on. Default:FALSE.Unlike
margin,marksreadspage(viaget_page_dims()) to work out where the margin area is, sopagemust equal the exact final output size — the same width/height you pass toggsave()— even ifncol/nroware supplied directly andpagewould otherwise be unused. Passing just the combined size of the grid of plots (i.e.pagewithoutmarginadded on) will place the marks in the wrong location, becauseggplot2::ggsave()will render a larger canvas thanmarkswas calculated for.- paginate
If
TRUE, create a list ofpatchworkobjects when the number of plots is greater than the number of spaces in the plot layout. Default toTRUE.
Value
A patchwork object, or (if n_bands doesn't fit on a single
page and paginate = TRUE) a list of patchwork objects — one per
page. Save with ggplot2::ggsave().
Examples
if (FALSE) { # \dontrun{
if (interactive() && is_installed(c("ggplot2", "patchwork"))) {
plot_band_page(get_card("Poker"), n = 54, n_bands = 4)
plot_band_page(
get_card("Poker"),
n = 54,
n_bands = 1,
position = "bottom-right"
)
}
} # }