Use as.factor(scan) for box plots
This commit is contained in:
@@ -158,7 +158,10 @@ update_gene_names <- function(df, sgd_gene_list) {
|
|||||||
|
|
||||||
generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_num", title, x_label = NULL, y_label = NULL) {
|
generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_num", title, x_label = NULL, y_label = NULL) {
|
||||||
# Base ggplot object with conditional y mapping
|
# Base ggplot object with conditional y mapping
|
||||||
if (!is.null(y_var)) {
|
if (plot_type == "box") {
|
||||||
|
# Ensure x_var is treated as a factor for box plots
|
||||||
|
plot <- ggplot(df, aes(x = as.factor(!!sym(x_var)), y = !!sym(y_var), color = !!sym(color_var)))
|
||||||
|
} else if (!is.null(y_var)) {
|
||||||
plot <- ggplot(df, aes(x = !!sym(x_var), y = !!sym(y_var), color = !!sym(color_var)))
|
plot <- ggplot(df, aes(x = !!sym(x_var), y = !!sym(y_var), color = !!sym(color_var)))
|
||||||
} else {
|
} else {
|
||||||
plot <- ggplot(df, aes(x = !!sym(x_var), color = !!sym(color_var)))
|
plot <- ggplot(df, aes(x = !!sym(x_var), color = !!sym(color_var)))
|
||||||
@@ -188,17 +191,15 @@ generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_
|
|||||||
return(plot)
|
return(plot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generate_and_save_plots <- function(df, output_dir, prefix, variables, include_qc = FALSE) {
|
generate_and_save_plots <- function(df, output_dir, prefix, variables, include_qc = FALSE) {
|
||||||
plots <- list()
|
plots <- list()
|
||||||
|
|
||||||
for (var in variables) {
|
for (var in variables) {
|
||||||
scatter_plot <-
|
scatter_plot <-
|
||||||
generate_plot(df, x_var = scan, y_var = !!sym(var), plot_type = "scatter",
|
generate_plot(df, x_var = "scan", y_var = var, plot_type = "scatter",
|
||||||
title = paste(prefix, "Scatter Plot for", var))
|
title = paste(prefix, "Scatter Plot for", var))
|
||||||
boxplot <-
|
boxplot <-
|
||||||
generate_plot(df, x_var = as.factor(scan), y_var = !!sym(var), plot_type = "box",
|
generate_plot(df, x_var = "scan", y_var = var, plot_type = "box",
|
||||||
title = paste(prefix, "Box Plot for", var))
|
title = paste(prefix, "Box Plot for", var))
|
||||||
|
|
||||||
plots[[paste0(var, "_scatter")]] <- scatter_plot
|
plots[[paste0(var, "_scatter")]] <- scatter_plot
|
||||||
@@ -207,13 +208,13 @@ generate_and_save_plots <- function(df, output_dir, prefix, variables, include_q
|
|||||||
|
|
||||||
if (include_qc) {
|
if (include_qc) {
|
||||||
plots[["Raw_L_vs_K"]] <-
|
plots[["Raw_L_vs_K"]] <-
|
||||||
generate_plot(df, x_var = L, y_var = K, plot_type = "scatter",
|
generate_plot(df, x_var = "L", y_var = "K", plot_type = "scatter",
|
||||||
title = "Raw L vs K before QC")
|
title = "Raw L vs K before QC")
|
||||||
plots[["Delta_bg_Density"]] <-
|
plots[["Delta_bg_Density"]] <-
|
||||||
generate_plot(df, x_var = delta_bg, plot_type = "density", color_var = "conc_num",
|
generate_plot(df, x_var = "delta_bg", plot_type = "density", color_var = "conc_num",
|
||||||
title = "Density plot for Delta Background by Conc All Data")
|
title = "Density plot for Delta Background by Conc All Data")
|
||||||
plots[["Delta_bg_Bar"]] <-
|
plots[["Delta_bg_Bar"]] <-
|
||||||
generate_plot(df, x_var = delta_bg, plot_type = "bar",
|
generate_plot(df, x_var = "delta_bg", plot_type = "bar",
|
||||||
title = "Bar plot for Delta Background by Conc All Data")
|
title = "Bar plot for Delta Background by Conc All Data")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,12 +425,13 @@ generate_rf_plots <- function(df_calculations, df_interactions, output_dir, file
|
|||||||
generate_summary_plots <- function(df, output_dir) {
|
generate_summary_plots <- function(df, output_dir) {
|
||||||
variables <- c("L", "K", "r", "AUC")
|
variables <- c("L", "K", "r", "AUC")
|
||||||
plot_list <- lapply(variables, function(var) {
|
plot_list <- lapply(variables, function(var) {
|
||||||
generate_plot(df, x_var = conc_num_factor, y_var = !!sym(var), plot_type = "scatter", title = paste("Summary Plot for", var))
|
generate_plot(df, x_var = "conc_num_factor", y_var = var, plot_type = "scatter", title = paste("Summary Plot for", var))
|
||||||
})
|
})
|
||||||
|
|
||||||
save_plots("Summary_Plots", plot_list, output_dir)
|
save_plots("Summary_Plots", plot_list, output_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
generate_cpp_correlation_plots <- function(df_na_rm, lm_list, output_dir) {
|
generate_cpp_correlation_plots <- function(df_na_rm, lm_list, output_dir) {
|
||||||
lm_summaries <- lapply(lm_list, summary)
|
lm_summaries <- lapply(lm_list, summary)
|
||||||
plot_titles <- c("Interaction L vs. Interaction K", "Interaction L vs. Interaction r", "Interaction L vs. Interaction AUC",
|
plot_titles <- c("Interaction L vs. Interaction K", "Interaction L vs. Interaction r", "Interaction L vs. Interaction AUC",
|
||||||
|
|||||||
Reference in New Issue
Block a user