Add back error bars to scatter plots

This commit is contained in:
2024-09-12 23:16:49 -04:00
parent 2f85b32a76
commit 1a2cd1a6c2

View File

@@ -461,7 +461,7 @@ generate_scatter_plot <- function(plot, config, interactive = FALSE) {
aes_params, shape = config$shape %||% 3,
size = config$size %||% 0.2,
position = if (!is.null(config$position) && config$position == "jitter") "jitter" else "identity")
# Add smooth line if specified
if (!is.null(config$add_smooth) && config$add_smooth) {
plot <- if (!is.null(config$lm_line)) {
@@ -471,6 +471,16 @@ generate_scatter_plot <- function(plot, config, interactive = FALSE) {
}
}
# Add error bars if specified
if (!is.null(config$error_bar) && config$error_bar) {
y_mean_col <- paste0("mean_", config$y_var)
y_sd_col <- paste0("sd_", config$y_var)
plot <- plot + geom_errorbar(aes(
ymin = !!sym(y_mean_col) - !!sym(y_sd_col),
ymax = !!sym(y_mean_col) + !!sym(y_sd_col)
), alpha = 0.3)
}
# Add x-axis customization if specified
if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
plot <- plot + scale_x_continuous(
@@ -615,10 +625,7 @@ generate_interaction_plot_configs <- function(df, variables) {
ylim_vals = var_info$ylim,
annotations = annotations,
lm_line = lm_line, # Precomputed linear model
error_bar = list(
ymin = 0 - (2 * df[[var_info$sd_col]][1]),
ymax = 0 + (2 * df[[var_info$sd_col]][1])
),
error_bar = TRUE,
x_breaks = unique(df$conc_num_factor),
x_labels = unique(as.character(df$conc_num)),
x_label = unique(df$Drug[1]),
@@ -637,7 +644,7 @@ generate_interaction_plot_configs <- function(df, variables) {
title = sprintf("%s %s (Boxplot)", df$OrfRep[1], df$Gene[1]),
ylim_vals = var_info$ylim,
annotations = annotations,
error_bar = FALSE, # Boxplots typically don't need error bars
error_bar = FALSE,
x_breaks = unique(df$conc_num_factor),
x_labels = unique(as.character(df$conc_num)),
x_label = unique(df$Drug[1]),