瀏覽代碼

Add grid.newpage() to paginate interaction plots

Bryan Roessler 6 月之前
父節點
當前提交
83576d6e94
共有 1 個文件被更改,包括 10 次插入8 次删除
  1. 10 8
      qhtcp-workflow/apps/r/calculate_interaction_zscores.R

+ 10 - 8
qhtcp-workflow/apps/r/calculate_interaction_zscores.R

@@ -7,6 +7,7 @@ suppressMessages({
   library("rlang")
   library("rlang")
   library("ggthemes")
   library("ggthemes")
   library("data.table")
   library("data.table")
+  library("grid")
   library("gridExtra")
   library("gridExtra")
   library("future")
   library("future")
   library("furrr")
   library("furrr")
@@ -662,11 +663,11 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs, page_width
       }
       }
 
 
       # Convert ggplot to plotly for interactive version
       # Convert ggplot to plotly for interactive version
-      # plotly_plot <- suppressWarnings(plotly::ggplotly(plot))
+      plotly_plot <- suppressWarnings(plotly::ggplotly(plot))
 
 
       # Store both static and interactive versions
       # Store both static and interactive versions
       static_plots[[i]] <- plot
       static_plots[[i]] <- plot
-      # plotly_plots[[i]] <- plotly_plot
+      plotly_plots[[i]] <- plotly_plot
     }
     }
 
 
     # Print the plots in the current group to the PDF
     # Print the plots in the current group to the PDF
@@ -682,6 +683,7 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs, page_width
         ncol = grid_layout$ncol,
         ncol = grid_layout$ncol,
         nrow = grid_layout$nrow
         nrow = grid_layout$nrow
       )
       )
+      grid.newpage()
     }
     }
   }
   }
 
 
@@ -1039,7 +1041,7 @@ generate_interaction_plot_configs <- function(df, type) {
   return(list(
   return(list(
     list(grid_layout = list(ncol = 2), plots = stats_plot_configs),
     list(grid_layout = list(ncol = 2), plots = stats_plot_configs),
     list(grid_layout = list(ncol = 2), plots = stats_boxplot_configs),
     list(grid_layout = list(ncol = 2), plots = stats_boxplot_configs),
-    list(grid_layout = list(ncol = 4), plots = delta_plot_configs[1:12])  # nrow calculated dynamically
+    list(grid_layout = list(ncol = 4), plots = delta_plot_configs[1:24])  # nrow calculated dynamically
   ))
   ))
 }
 }
 
 
@@ -1429,10 +1431,10 @@ main <- function() {
     )
     )
 
 
     # Parallelize background and quality control plot generation
     # Parallelize background and quality control plot generation
-    furrr::future_map(plot_configs, function(config) {
-      generate_and_save_plots(config$out_dir, config$filename, config$plot_configs,
-        page_width = config$page_width, page_height = config$page_height)
-    }, .options = furrr_options(seed = TRUE))
+    # furrr::future_map(plot_configs, function(config) {
+    #   generate_and_save_plots(config$out_dir, config$filename, config$plot_configs,
+    #     page_width = config$page_width, page_height = config$page_height)
+    # }, .options = furrr_options(seed = TRUE))
 
 
     # Loop over background strains
     # Loop over background strains
     # TODO currently only tested against one strain, if we want to do multiple strains we'll
     # TODO currently only tested against one strain, if we want to do multiple strains we'll
@@ -1492,7 +1494,7 @@ main <- function() {
 
 
       message("Generating reference interaction plots")
       message("Generating reference interaction plots")
       reference_plot_configs <- generate_interaction_plot_configs(df_interactions_reference_joined, "reference")
       reference_plot_configs <- generate_interaction_plot_configs(df_interactions_reference_joined, "reference")
-      generate_and_save_plots(out_dir, "interaction_plots_reference", reference_plot_configs, page_width = 16, page_height = 16)
+      generate_and_save_plots(out_dir, "interaction_plots_reference", reference_plot_configs, page_width = 18, page_height = 16)
 
 
       message("Setting missing deletion values to the highest theoretical value at each drug conc for L")
       message("Setting missing deletion values to the highest theoretical value at each drug conc for L")
       df_deletion <- df_na_stats %>% # formerly X2
       df_deletion <- df_na_stats %>% # formerly X2