Paginate plot groups

This commit is contained in:
2024-10-02 15:26:14 -04:00
parent 744627fcb6
commit 5332cf3fbc

View File

@@ -415,6 +415,7 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
# Open the PDF device once for all plots # Open the PDF device once for all plots
pdf(file.path(out_dir, paste0(filename, ".pdf")), width = 16, height = 9) pdf(file.path(out_dir, paste0(filename, ".pdf")), width = 16, height = 9)
# Loop through each plot group
for (group in plot_groups) { for (group in plot_groups) {
static_plots <- list() static_plots <- list()
plotly_plots <- list() plotly_plots <- list()
@@ -496,7 +497,7 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
plotly_plots[[i]] <- plotly_plot plotly_plots[[i]] <- plotly_plot
} }
# Print the plots to the PDF (one page per plot or in a grid) # Print the plots in the current group to the PDF
if (is.null(grid_layout)) { if (is.null(grid_layout)) {
# Print each plot individually on separate pages if no grid layout is specified # Print each plot individually on separate pages if no grid layout is specified
for (plot in static_plots) { for (plot in static_plots) {
@@ -510,12 +511,17 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
nrow = grid_layout$nrow nrow = grid_layout$nrow
) )
} }
# Add a new page for the next group, if it exists
if (length(plot_groups) > 1) {
grid.newpage()
}
} }
# Close the PDF device after all plots are done # Close the PDF device after all plots are done
dev.off() dev.off()
# Optional: Uncomment and save the interactive HTML version if needed # Save HTML file with interactive plots if needed
# out_html_file <- file.path(out_dir, paste0(filename, ".html")) # out_html_file <- file.path(out_dir, paste0(filename, ".html"))
# message("Saving combined HTML file: ", out_html_file) # message("Saving combined HTML file: ", out_html_file)
# htmltools::save_html( # htmltools::save_html(