Add error bar color controls

This commit is contained in:
2024-10-02 13:47:57 -04:00
parent df4c3352e3
commit 6015f7faa8

View File

@@ -458,6 +458,30 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
if (!is.null(config$y_label)) plot <- plot + ylab(config$y_label) if (!is.null(config$y_label)) plot <- plot + ylab(config$y_label)
if (!is.null(config$coord_cartesian)) plot <- plot + coord_cartesian(ylim = config$coord_cartesian) if (!is.null(config$coord_cartesian)) plot <- plot + coord_cartesian(ylim = config$coord_cartesian)
# Add error bars if specified
if (!is.null(config$error_bar) && config$error_bar) {
error_bar_color <- if (!is.null(config$error_bar_params$color)) {
config$error_bar_params$color
} else {
"red"
}
if (!is.null(config$error_bar_params$ymin) && !is.null(config$error_bar_params$ymax)) {
ymin_value <- config$error_bar_params$ymin
ymax_value <- config$error_bar_params$ymax
} else {
y_mean_col <- paste0("mean_", config$y_var)
y_sd_col <- paste0("sd_", config$y_var)
ymin_value <- !!sym(y_mean_col) - !!sym(y_sd_col)
ymax_value <- !!sym(y_mean_col) + !!sym(y_sd_col)
}
plot <- plot + geom_errorbar(aes(
ymin = ymin_value,
ymax = ymax_value,
color = error_bar_color))
}
plotly_plot <- suppressWarnings(plotly::ggplotly(plot)) plotly_plot <- suppressWarnings(plotly::ggplotly(plot))
static_plots[[i]] <- plot static_plots[[i]] <- plot
@@ -496,7 +520,7 @@ generate_scatter_plot <- function(plot, config) {
size <- if (!is.null(config$size)) config$size else 1.5 size <- if (!is.null(config$size)) config$size else 1.5
position <- position <-
if (!is.null(config$position) && config$position == "jitter") { if (!is.null(config$position) && config$position == "jitter") {
position_jitter(width = 0.1, height = 0) position_jitter(width = 0.2, height = 0)
} else { } else {
"identity" "identity"
} }
@@ -575,29 +599,6 @@ generate_scatter_plot <- function(plot, config) {
) )
} }
} }
# Add error bars if specified
if (!is.null(config$error_bar) && config$error_bar && !is.null(config$y_var)) {
if (!is.null(config$error_bar_params)) {
error_bar_color <- if (!is.null(config$error_bar_params$color)) {
config$error_bar_params$color
} else {
"red"
}
plot <- plot + geom_errorbar(aes(
ymin = config$error_bar_params$ymin,
ymax = config$error_bar_params$ymax,
color = error_bar_color))
} else {
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),
color = "red"))
}
}
# Customize X-axis if specified # Customize X-axis if specified
if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) { if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
@@ -755,6 +756,9 @@ generate_interaction_plot_configs <- function(df, type) {
title = sprintf("%s Scatter RF for %s with SD", OrfRep, var), title = sprintf("%s Scatter RF for %s with SD", OrfRep, var),
coord_cartesian = y_limits, coord_cartesian = y_limits,
error_bar = TRUE, error_bar = TRUE,
error_bar_params = list(
color = "red",
),
x_breaks = unique(df$conc_num_factor_factor), x_breaks = unique(df$conc_num_factor_factor),
x_labels = as.character(unique(df$conc_num)), x_labels = as.character(unique(df$conc_num)),
position = "jitter", position = "jitter",
@@ -825,7 +829,8 @@ generate_interaction_plot_configs <- function(df, type) {
error_bar = TRUE, error_bar = TRUE,
error_bar_params = list( error_bar_params = list(
ymin = 0 - (2 * WT_sd_value), ymin = 0 - (2 * WT_sd_value),
ymax = 0 + (2 * WT_sd_value) ymax = 0 + (2 * WT_sd_value),
color = "black"
), ),
smooth = TRUE, smooth = TRUE,
x_breaks = unique(group_data$conc_num_factor_factor), x_breaks = unique(group_data$conc_num_factor_factor),