Parcourir la source

Add correct lm smoothing colors

Bryan Roessler il y a 7 mois
Parent
commit
d64d6d18cc
1 fichiers modifiés avec 15 ajouts et 13 suppressions
  1. 15 13
      qhtcp-workflow/apps/r/calculate_interaction_zscores.R

+ 15 - 13
qhtcp-workflow/apps/r/calculate_interaction_zscores.R

@@ -494,20 +494,22 @@ generate_scatter_plot <- function(plot, config) {
   }
   
   # Add Smooth Line if specified
-  if (!is.null(config$add_smooth) && config$add_smooth) {
+  if (!is.null(config$smooth) && config$smooth) {
+    smooth_color <- if (!is.null(config$smooth_color)) config$smooth_color else "blue"
+    
     if (!is.null(config$lm_line)) {
       plot <- plot +
         geom_abline(
           intercept = config$lm_line$intercept,
           slope = config$lm_line$slope,
-          color = "blue"
+          color = smooth_color
         )
     } else {
       plot <- plot +
         geom_smooth(
           method = "lm",
           se = FALSE,
-          color = "blue"
+          color = smooth_color
         )
     }
   }
@@ -851,27 +853,25 @@ generate_rank_plot_configs <- function(df_filtered, variables, is_lm = FALSE, ov
     
   # Avg ZScore and Rank Avg ZScore Plots for r, L, K, and AUC
   for (variable in variables) {
-    for (plot_type in c("Avg_Zscore_vs_lm", "Rank_Avg_Zscore_vs_lm")) {
+    for (plot_type in c("Avg Zscore vs lm", "Rank Avg Zscore vs lm")) {
+
+      title <- paste(plot_type, variable)
+
       # Define specific variables based on plot type
-      if (plot_type == "Avg_Zscore_vs_lm") {
+      if (plot_type == "Avg Zscore vs lm") {
         x_var <- paste0("Avg_Zscore_", variable)
         y_var <- paste0("Z_lm_", variable)
-        title <- paste("Avg Zscore vs lm", variable)
         rectangles <- list(
           list(xmin = -2, xmax = 2, ymin = -2, ymax = 2,
             fill = NA, color = "grey20", alpha = 0.1
           )
         )
-      } else {
+      } else if (plot_type == "Rank Avg Zscore vs lm") {
         x_var <- paste0("Rank_", variable)
         y_var <- paste0("Rank_lm_", variable)
-        title <- paste("Rank Avg Zscore vs lm", variable)
         rectangles <- NULL
       }
 
-      print(summary(df_filtered[[x_var]]))
-      print(summary(df_filtered[[y_var]]))
-      
       # Fit linear model
       lm_model <- lm(as.formula(paste(y_var, "~", x_var)), data = df_filtered)
       lm_summary <- summary(lm_model)
@@ -904,7 +904,8 @@ generate_rank_plot_configs <- function(df_filtered, variables, is_lm = FALSE, ov
         ),
         shape = 3,
         size = 0.1,
-        add_smooth = TRUE,
+        smooth = TRUE,
+        smooth_color = "black",
         lm_line = list(intercept = intercept, slope = slope),
         legend_position = "right",
         color_var = if (overlap_color) "Overlap" else NULL,
@@ -955,7 +956,8 @@ generate_correlation_plot_configs <- function(df) {
           color = "black"
         )
       ),
-      add_smooth = TRUE,  # Add regression line
+      smooth = TRUE,
+      smooth_color = "tomato3",
       lm_line = list(intercept = coef(lm_model)[1], slope = coef(lm_model)[2]),
       legend_position = "right",
       shape = 3,