Skip to content

Instantly share code, notes, and snippets.

@swo
Created November 7, 2023 15:26
Show Gist options
  • Save swo/0c574830779c8e750307113cfe9f2f8f to your computer and use it in GitHub Desktop.
Save swo/0c574830779c8e750307113cfe9f2f8f to your computer and use it in GitHub Desktop.
Make a multipage pdf with ggplot
#' @param list_of_plots plots to save, one per page
#' @param path path to output pdf
#' @param ... additional arguments to `ggplot2::ggsave()`
save_multipage_pdf <- function(list_of_plots, path, ...) {
# path must end with .pdf
stopifnot(grepl("\\.pdf$", path))
ggplot2::ggsave(
path,
gridExtra::marrangeGrob(list_of_plots, ncol = 1, nrow = 1)
...
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment