diff --git a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R index 025d02f0..ef756191 100644 --- a/qhtcp-workflow/apps/r/calculate_interaction_zscores.R +++ b/qhtcp-workflow/apps/r/calculate_interaction_zscores.R @@ -376,14 +376,27 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la plot <- plot + geom_smooth(method = "lm", se = FALSE) } } - - plot <- plot + - geom_errorbar(aes( - ymin = !!sym(paste0("mean_", config$y_var)) - !!sym(paste0("sd_", config$y_var)), - ymax = !!sym(paste0("mean_", config$y_var)) + !!sym(paste0("sd_", config$y_var))), - width = 0.1) + - geom_point(aes(y = !!sym(paste0("mean_", config$y_var))), size = 0.6) - + + if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label) && config$plot_type != "box") { + plot <- plot + scale_x_continuous( + name = config$x_label, + breaks = config$x_breaks, + labels = config$x_labels + ) + } + + if (!is.null(config$ylim_vals)) { + plot <- plot + scale_y_continuous(limits = config$ylim_vals) + } + + if (!is.null(config$delta_bg_point) && config$delta_bg_point) { + plot <- plot + + geom_errorbar(aes( + ymin = !!sym(paste0("mean_", config$y_var)) - !!sym(paste0("sd_", config$y_var)), + ymax = !!sym(paste0("mean_", config$y_var)) + !!sym(paste0("sd_", config$y_var))), + width = 0.1) + + geom_point(aes(y = !!sym(paste0("mean_", config$y_var))), size = 0.6) + } plot }, @@ -414,25 +427,19 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope, color = "tomato3") + annotate("text", x = 0, y = 0, label = config$correlation_text), - "box" = plot + geom_boxplot(), + "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") { + plot <- plot + scale_x_discrete( + name = config$x_label, + breaks = config$x_breaks, + labels = config$x_labels + ) + }}, "density" = plot + geom_density(), "bar" = plot + geom_bar() ) - # Conditionally apply scale_x_continuous if x_breaks, x_labels, and x_label are present - 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, - labels = config$x_labels - ) - } - - # Conditionally apply scale_y_continuous if ylim_vals is present - if (!is.null(config$ylim_vals)) { - plot <- plot + scale_y_continuous(limits = config$ylim_vals) - } - plot })