diff --git a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R index ef960e45..599ffea6 100644 --- a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R +++ b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R @@ -415,6 +415,7 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) { # Open the PDF device once for all plots pdf(file.path(out_dir, paste0(filename, ".pdf")), width = 16, height = 9) + # Loop through each plot group for (group in plot_groups) { static_plots <- list() plotly_plots <- list() @@ -496,7 +497,7 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) { 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)) { # Print each plot individually on separate pages if no grid layout is specified for (plot in static_plots) { @@ -510,12 +511,17 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) { 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 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")) # message("Saving combined HTML file: ", out_html_file) # htmltools::save_html(