| facet_wrap_paginate {ggforce} | R Documentation |
This extension to facet_wrap will allow you to split
a facetted plot over multiple pages. You define a number of rows and columns
per page as well as the page number to plot, and the function will
automatically only plot the correct panels. Usually this will be put in a
loop to render all pages one by one.
facet_wrap_paginate(facets, nrow = NULL, ncol = NULL, scales = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = NULL, drop = TRUE, dir = "h", strip.position = "top", page = 1)
facets |
Either a formula or character vector. Use either a
one sided formula, |
nrow |
Number of rows and columns. |
ncol |
Number of rows and columns |
scales |
should Scales be fixed ( |
shrink |
If |
labeller |
A function that takes one data frame of labels and
returns a list or data frame of character vectors. Each input
column corresponds to one factor. Thus there will be more than
one with formulae of the type |
as.table |
If |
switch |
By default, the labels are displayed on the top and
right of the plot. If |
drop |
If |
dir |
Direction: either "h" for horizontal, the default, or "v", for vertical. |
strip.position |
By default, the labels are displayed on the top of
the plot. Using |
page |
The page to draw |
If either ncol or nrow is NULL this function will
fall back to the standard facet_wrap functionality.
Other ggforce.facets: facet_grid_paginate,
facet_zoom
# Calculate the number of pages with 9 panels per page
n_pages <- ceiling(
length(levels(diamonds$cut)) * length(levels(diamonds$clarity)) / 9
)
# Draw each page
for (i in seq_len(n_pages)) {
ggplot(diamonds) +
geom_point(aes(carat, price), alpha = 0.1) +
facet_wrap_paginate(~cut:clarity, ncol = 3, nrow = 3, page = i)
}