Fix default error bar calculations

This commit is contained in:
2024-10-02 14:01:09 -04:00
parent 8e28accb80
commit 964d2ad9b2

View File

@@ -433,7 +433,7 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
aes_mapping <- aes(x = .data[[config$x_var]]) aes_mapping <- aes(x = .data[[config$x_var]])
} }
} else { } else {
# For other plot types # For scatter and other plot types
if (!is.null(config$y_var) && !is.null(config$color_var)) { if (!is.null(config$y_var) && !is.null(config$color_var)) {
aes_mapping <- aes(x = .data[[config$x_var]], y = .data[[config$y_var]], color = .data[[config$color_var]]) aes_mapping <- aes(x = .data[[config$x_var]], y = .data[[config$y_var]], color = .data[[config$color_var]])
} else if (!is.null(config$y_var)) { } else if (!is.null(config$y_var)) {
@@ -466,14 +466,15 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
"red" "red"
} }
# Use error_bar_params if provided, otherwise calculate from mean and sd
if (!is.null(config$error_bar_params$ymin) && !is.null(config$error_bar_params$ymax)) { if (!is.null(config$error_bar_params$ymin) && !is.null(config$error_bar_params$ymax)) {
ymin_value <- config$error_bar_params$ymin ymin_value <- config$error_bar_params$ymin
ymax_value <- config$error_bar_params$ymax ymax_value <- config$error_bar_params$ymax
} else { } else {
y_mean_col <- paste0("mean_", config$y_var) y_mean_col <- paste0("mean_", config$y_var)
y_sd_col <- paste0("sd_", config$y_var) y_sd_col <- paste0("sd_", config$y_var)
ymin_value <- !!sym(y_mean_col) - !!sym(y_sd_col) ymin_value <- df[[y_mean_col]] - df[[y_sd_col]]
ymax_value <- !!sym(y_mean_col) + !!sym(y_sd_col) ymax_value <- df[[y_mean_col]] + df[[y_sd_col]]
} }
plot <- plot + geom_errorbar(aes( plot <- plot + geom_errorbar(aes(