Bryan Roessler 7 месяцев назад
Родитель
Сommit
f90cb25f91
1 измененных файлов с 17 добавлено и 6 удалено
  1. 17 6
      qhtcp-workflow/apps/r/calculate_interaction_zscores.R

+ 17 - 6
qhtcp-workflow/apps/r/calculate_interaction_zscores.R

@@ -377,7 +377,7 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
           }
         }
 
-        if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label) && config$plot_type != "box") {
+        if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
           plot <- plot + scale_x_continuous(
             name = config$x_label,
             breaks = config$x_breaks,
@@ -397,6 +397,11 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
               width = 0.1) +
             geom_point(aes(y = !!sym(paste0("mean_", config$y_var))), size = 0.6)
         }
+
+        if (!is.null(config$coord_cartesian)) {
+          plot <- plot + coord_cartesian(ylim = config$coord_cartesian)
+        }
+
         plot
       },
       
@@ -429,13 +434,18 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
       
       "box" = {
         plot <- plot + geom_boxplot()
-        if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label) && config$plot_type == "box") {
+        if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
           plot <- plot + scale_x_discrete(
             name = config$x_label,
             breaks = config$x_breaks,
             labels = config$x_labels
           )
-        }},
+        }
+        if (!is.null(config$coord_cartesian)) {
+          plot <- plot + coord_cartesian(ylim = config$coord_cartesian)
+        }
+        plot
+      },
       "density" = plot + geom_density(),
       "bar" = plot + geom_bar()
     )
@@ -517,7 +527,8 @@ generate_interaction_plot_configs <- function(df, variables) {
       x_label = unique(df$Drug[1]),
       shape = 3,
       size = 0.6,
-      position = "jitter"
+      position = "jitter",
+      coord_cartesian = c(0, max(var_info$ylim))  # You can customize this per plot as needed
     )
 
     # Add box plot configuration for this variable
@@ -532,14 +543,14 @@ generate_interaction_plot_configs <- function(df, variables) {
       error_bar = FALSE,  # Boxplots typically don't need error bars
       x_breaks = unique(df$conc_num_factor),
       x_labels = unique(as.character(df$conc_num)),
-      x_label = unique(df$Drug[1])
+      x_label = unique(df$Drug[1]),
+      coord_cartesian = c(0, max(var_info$ylim))  # Customize this as needed
     )
   }
 
   return(configs)
 }
 
-
 # Adjust missing values and calculate ranks
 adjust_missing_and_rank <- function(df, variables) {