Add boxplots to interaction plots

This commit is contained in:
2024-09-09 23:34:18 -04:00
parent 356b47106e
commit 4e15fb80fb

View File

@@ -358,7 +358,7 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
# If grid_layout is provided, arrange plots in a grid and save in a single PDF
if (!is.null(grid_layout)) {
pdf(file.path(output_dir, paste0(file_name, "_grid.pdf")), width = 14, height = 9)
pdf(file.path(output_dir, paste0(file_name, ".pdf")), width = 14, height = 9)
# Loop through plots in chunks defined by ncol and nrow
for (start_idx in seq(1, length(plots), by = grid_layout$ncol * grid_layout$nrow)) {
@@ -426,7 +426,7 @@ interaction_plot_configs <- function(df, variables) {
ifelse(variable == "r", -0.45, -4500))), label = paste("SM =", df$SM))
)
# Append a new plot configuration for each variable
# Add scatter plot configuration for this variable
plot_configs[[length(plot_configs) + 1]] <- list(
df = df,
x_var = "conc_num_factor",
@@ -443,11 +443,27 @@ interaction_plot_configs <- function(df, variables) {
x_labels = unique(as.character(df$conc_num)),
x_label = unique(df$Drug[1])
)
# Add box plot configuration for this variable
plot_configs[[length(plot_configs) + 1]] <- list(
df = df,
x_var = "conc_num_factor",
y_var = variable,
plot_type = "box",
title = sprintf("%s %s (Boxplot)", df$OrfRep[1], df$Gene[1]),
ylim_vals = ylim_vals,
annotations = annotations,
error_bar = FALSE, # Boxplots typically don't need error bars
x_breaks = unique(df$conc_num_factor),
x_labels = unique(as.character(df$conc_num)),
x_label = unique(df$Drug[1])
)
}
return(plot_configs)
}
correlation_plot_configs <- function(df, lm_list, lm_summaries) {
lapply(seq_along(lm_list), function(i) {
r_squared <- round(lm_summaries[[i]]$r.squared, 3)