Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow saving PDF pages #6187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5093.

Briefly, it allows ggsave(plot) to be a list and draws every element in that list.

While this works, it has a few drawbacks:

  • No warning is thrown when device != "pdf". This is because it is hard to detect whether the current device is a PDF device that supports the onefile argument.
  • I don't think there is a way to set different bg for every page, so instead we don't use the trick where we set the background to the plot background colour.

Example usage:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
p <- ggplot(mpg, aes(displ, hwy)) + geom_point()

pl <- list(
  p + ggtitle("First"),
  p + ggtitle("Second"),
  p + ggtitle("Last")
)

# `onefile = TRUE` is default, but clarifies intent
ggsave("pages.pdf", plot = pl, device = "pdf", onefile = TRUE)
#> Saving 7 x 5 in image

Created on 2024-11-15 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New feature to allow ggsave to save multiple plots to separate pages of pdf
1 participant