Skip to content

Commit

Permalink
allow saving pages
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Nov 15, 2024
1 parent f468053 commit b682c8a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/save.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
bg <- calc_element("plot.background", plot_theme(plot))$fill %||% "transparent"
}
old_dev <- grDevices::dev.cur()
Expand All @@ -111,7 +111,10 @@ ggsave <- function(filename, plot = get_last_plot(),
grDevices::dev.off()
if (old_dev > 1) grDevices::dev.set(old_dev) # restore old device unless null device
}))
grid.draw(plot)
if (!is_bare_list(plot)) {
plot <- list(plot)
}
lapply(plot, grid.draw)

invisible(filename)
}
Expand Down

0 comments on commit b682c8a

Please sign in to comment.