소스 검색

Before generate_and_save_plots() refactor

Bryan Roessler 7 달 전
부모
커밋
2a7f460897
1개의 변경된 파일5개의 추가작업 그리고 7개의 파일을 삭제
  1. 5 7
      qhtcp-workflow/apps/r/calculate_interaction_zscores.R

+ 5 - 7
qhtcp-workflow/apps/r/calculate_interaction_zscores.R

@@ -409,7 +409,7 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
 
     # Setting legend position, titles, and labels
     legend_position <- config$legend_position %||% "bottom"
-    plot <- plot + ggtitle(config$title) + theme_Publication(legend_position = legend_position)
+    plot <- plot + ggtitle(config$title) + theme_publication(legend_position = legend_position)
     
     if (!is.null(config$x_label)) plot <- plot + xlab(config$x_label)
     if (!is.null(config$y_label)) plot <- plot + ylab(config$y_label)
@@ -439,12 +439,11 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
     
     dev.off()
     
-    # Save as HTML (optional)
     plotly_plots <- lapply(plots, function(plot) {
       suppressWarnings(ggplotly(plot) %>% layout(legend = list(orientation = "h")))
     })
     combined_plot <- subplot(plotly_plots, nrows = grid_layout$nrow, margin = 0.05)
-    saveWidget(combined_plot, file = file.path(output_dir, paste0(file_name, "_grid.html")), selfcontained = TRUE)
+    saveWidget(combined_plot, file = file.path(output_dir, paste0(file_name, ".html")), selfcontained = TRUE)
     
   } else {
     # Save individual plots to PDF
@@ -603,7 +602,8 @@ generate_correlation_plot_configs <- function(df, variables) {
       plot_type = "correlation",
       title = paste("Avg Zscore vs lm", variable),
       color_var = "Overlap",
-      correlation_text = paste("R-squared =", round(df[[lm_r_squared_col]][1], 2))
+      correlation_text = paste("R-squared =", round(df[[lm_r_squared_col]][1], 2)),
+      legend_position = "right"
     )
   }
 
@@ -966,6 +966,7 @@ main <- function() {
         group_by(across(all_of(group_vars))) %>%
           filter(!is.na(Z_lm_L) | !is.na(Avg_Zscore_L))
       
+      # Final filtered correaltion calculations and plots
       zscores_interactions_filtered <- zscores_interactions_filtered %>%
         mutate(
           Overlap = case_when(
@@ -988,7 +989,6 @@ main <- function() {
         generate_rank_plot_configs(zscores_interactions_filtered, "Rank_L", "Avg_Zscore_L", "L"),
         generate_rank_plot_configs(zscores_interactions_filtered, "Rank_K", "Avg_Zscore_K", "K")
       )
-      
       generate_and_save_plots(output_dir = out_dir, file_name = "RankPlots",
         plot_configs = rank_plot_configs, grid_layout = list(ncol = 3, nrow = 2))
       
@@ -996,14 +996,12 @@ main <- function() {
         generate_rank_plot_configs(zscores_interactions_filtered, "Rank_lm_L", "Z_lm_L", "L", is_lm = TRUE),
         generate_rank_plot_configs(zscores_interactions_filtered, "Rank_lm_K", "Z_lm_K", "K", is_lm = TRUE)
       )
-      
       generate_and_save_plots(output_dir = out_dir, file_name = "RankPlots_lm",
         plot_configs = rank_lm_plot_configs, grid_layout = list(ncol = 3, nrow = 2))
 
       correlation_plot_configs <- generate_correlation_plot_configs(zscores_interactions_filtered, variables)
       generate_and_save_plots(output_dir = out_dir, file_name = "Avg_Zscore_vs_lm_NA_rm",
         plot_configs = correlation_plot_configs, grid_layout = list(ncol = 2, nrow = 2))
-
     })
   })
 }