Browse Source

Restore default aes colors

Bryan Roessler 6 months ago
parent
commit
039c6c1388
1 changed files with 21 additions and 6 deletions
  1. 21 6
      qhtcp-workflow/apps/r/calculate_interaction_zscores.R

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

@@ -151,7 +151,7 @@ load_and_filter_data <- function(easy_results_file, sd = 3) {
       OrfRep = if_else(ORF == "YDL227C", "YDL227C", OrfRep), # should these be hardcoded?
       conc_num = as.numeric(gsub("[^0-9\\.]", "", Conc)),
       conc_num_factor = as.numeric(as.factor(conc_num)) - 1, # for legacy purposes
-      conc_num_factor_factor = factor(conc_num)
+      conc_num_factor_factor = as.factor(conc_num)
     )
 
   return(df)
@@ -405,12 +405,23 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
 
     # Define aes_mapping and handle color_var defaulting
     aes_mapping <- if (config$plot_type == "bar") {
-      aes(x = .data[[config$x_var]], fill = ifelse(!is.null(config$color_var), .data[[config$color_var]], "black"),
-        color = ifelse(!is.null(config$color_var), .data[[config$color_var]], "black"))
+      if (!is.null(config$color_var)) {
+        aes(x = .data[[config$x_var]], fill = .data[[config$color_var]], color = .data[[config$color_var]])
+      } else {
+        aes(x = .data[[config$x_var]])
+      }
     } else if (config$plot_type == "density") {
-      aes(x = .data[[config$x_var]], color = ifelse(!is.null(config$color_var), .data[[config$color_var]], "black"))
+      if (!is.null(config$color_var)) {
+        aes(x = .data[[config$x_var]], color = .data[[config$color_var]])
+      } else {
+        aes(x = .data[[config$x_var]])
+      }
     } else {
-      aes(x = .data[[config$x_var]], y = .data[[config$y_var]], color = ifelse(!is.null(config$color_var), .data[[config$color_var]], "black"))
+      if (!is.null(config$color_var)) {
+        aes(x = .data[[config$x_var]], y = .data[[config$y_var]], color = .data[[config$color_var]])
+      } else {
+        aes(x = .data[[config$x_var]], y = .data[[config$y_var]])
+      }
     }
 
     # Apply theme_publication with legend_position
@@ -451,7 +462,11 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
   dev.off()
 
   # Save combined interactive HTML plots
-  combined_plot <- plotly::subplot(plotly_plots, nrows = grid_nrow, ncols = grid_ncol, margin = 0.05)
+  if (length(plotly_plots) == 1) {
+    combined_plot <- plotly_plots[[1]]
+  } else {
+    combined_plot <- plotly::subplot(plotly_plots, nrows = grid_nrow, ncols = grid_ncol, margin = 0.05)
+  }
   html_file <- file.path(out_dir, paste0(filename, ".html"))
   saveWidget(combined_plot, file = html_file, selfcontained = TRUE)
 }