Use WT values for error bars

This commit is contained in:
2024-10-02 16:55:56 -04:00
parent 850a34d30f
commit 4265663e17
2 changed files with 26 additions and 11 deletions

View File

@@ -463,9 +463,21 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
# Add error bars if specified # Add error bars if specified
if (!is.null(config$error_bar) && config$error_bar) { if (!is.null(config$error_bar) && config$error_bar) {
error_bar_color <- config$error_bar_params$color %||% "red" error_bar_color <- if (!is.null(config$error_bar_params$color)) {
y_mean_col <- paste0("mean_", config$y_var) config$error_bar_params$color
y_sd_col <- paste0("sd_", config$y_var) } else {
"red"
}
y_mean_col <- paste0("mean_mean_", config$y_var)
# Dynamically set y_sd_col based on the provided prefix in error_bar_params
y_sd_prefix <- if (!is.null(config$error_bar_params$y_sd_prefix)) {
config$error_bar_params$y_sd_prefix
} else {
"sd_"
}
y_sd_col <- paste0(y_sd_prefix, config$y_var)
if (!is.null(config$error_bar_params$center_point)) { if (!is.null(config$error_bar_params$center_point)) {
plot <- plot + geom_point(aes( plot <- plot + geom_point(aes(
@@ -489,6 +501,8 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
} }
} }
# Convert ggplot to plotly for interactive version # Convert ggplot to plotly for interactive version
plotly_plot <- suppressWarnings(plotly::ggplotly(plot)) plotly_plot <- suppressWarnings(plotly::ggplotly(plot))
@@ -511,19 +525,18 @@ generate_and_save_plots <- function(out_dir, filename, plot_configs) {
nrow = grid_layout$nrow nrow = grid_layout$nrow
) )
} }
} }
# Close the PDF device after all plots are done # Close the PDF device after all plots are done
dev.off() dev.off()
# Save HTML file with interactive plots if needed # Save HTML file with interactive plots if needed
# out_html_file <- file.path(out_dir, paste0(filename, ".html")) out_html_file <- file.path(out_dir, paste0(filename, ".html"))
# message("Saving combined HTML file: ", out_html_file) message("Saving combined HTML file: ", out_html_file)
# htmltools::save_html( htmltools::save_html(
# htmltools::tagList(plotly_plots), htmltools::tagList(plotly_plots),
# file = out_html_file file = out_html_file
# ) )
} }
generate_scatter_plot <- function(plot, config) { generate_scatter_plot <- function(plot, config) {
@@ -650,7 +663,7 @@ generate_scatter_plot <- function(plot, config) {
label = annotation$label, label = annotation$label,
hjust = ifelse(is.null(annotation$hjust), 0.5, annotation$hjust), hjust = ifelse(is.null(annotation$hjust), 0.5, annotation$hjust),
vjust = ifelse(is.null(annotation$vjust), 0.5, annotation$vjust), vjust = ifelse(is.null(annotation$vjust), 0.5, annotation$vjust),
size = ifelse(is.null(annotation$size), 6, annotation$size), size = ifelse(is.null(annotation$size), 3, annotation$size),
color = ifelse(is.null(annotation$color), "black", annotation$color) color = ifelse(is.null(annotation$color), "black", annotation$color)
) )
} }
@@ -759,6 +772,7 @@ generate_interaction_plot_configs <- function(df, type) {
plot_config$title <- sprintf("%s Scatter RF for %s with SD", OrfRep, var) plot_config$title <- sprintf("%s Scatter RF for %s with SD", OrfRep, var)
plot_config$error_bar <- TRUE plot_config$error_bar <- TRUE
plot_config$error_bar_params <- list( plot_config$error_bar_params <- list(
y_sd_prefix = "WT_sd_",
color = "red", color = "red",
center_point = TRUE center_point = TRUE
) )

View File

@@ -1442,6 +1442,7 @@ wrapper calculate_interaction_zscores
# * We are using standard error bars using the same se values as the data now (includes Bessel's correction) # * We are using standard error bars using the same se values as the data now (includes Bessel's correction)
# * Plate analysis error bars and some others will be slightly different # * Plate analysis error bars and some others will be slightly different
# * Can be changed back but better to have plots reflect data, no? # * Can be changed back but better to have plots reflect data, no?
# * Dynamically generate axis limits based on data (if desired)
# #
# INPUT # INPUT
# #