-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: main
Are you sure you want to change the base?
Allow saving PDF pages #6187
Conversation
@@ -102,7 +102,7 @@ ggsave <- function(filename, plot = get_last_plot(), | |||
dim <- plot_dim(c(width, height), scale = scale, units = units, | |||
limitsize = limitsize, dpi = dpi) | |||
|
|||
if (is_null(bg)) { | |||
if (is_null(bg) && is.ggplot(plot)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case a list is passed in, I think we should just grab the bg from the first plot in the list rather than completely ignore it
if (!is_bare_list(plot)) { | ||
plot <- list(plot) | ||
} | ||
lapply(plot, grid.draw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a grid.newpage()
in between every draw call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I would have thought so as well. This would make sense, but grid.draw.ggplot()
calls print.ggplot()
, which has the following clause:
Line 196 in 8efc700
if (newpage) grid.newpage() |
which gets activated by default. For this reason, grid.newpage()
gets invoked every loop for a list of ggplots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yeah... forgot it was a ggplot object 🙈
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:
device != "pdf"
. This is because it is hard to detect whether the current device is a PDF device that supports theonefile
argument.bg
for every page, so instead we don't use the trick where we set the background to the plot background colour.Example usage:
Created on 2024-11-15 with reprex v2.1.1