Add y var to stat_summary()

This commit is contained in:
2024-09-01 04:37:02 -04:00
parent 1bd3f9c4b4
commit 48311fda3b

View File

@@ -158,13 +158,17 @@ 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 # Base ggplot object
plot <- ggplot(df, aes(x = {{x_var}}, color = {{color_var}})) if (!is.null(y_var)) {
plot <- ggplot(df, aes(x = {{x_var}}, y = {{y_var}}, color = {{color_var}}))
} else {
plot <- ggplot(df, aes(x = {{x_var}}, color = {{color_var}}))
}
# Handle different plot types # Handle different plot types
if (plot_type == "scatter") { if (plot_type == "scatter") {
plot <- plot + geom_point(shape = 3, size = 0.2, position = "jitter") + plot <- plot + geom_point(shape = 3, size = 0.2, position = "jitter") +
stat_summary(fun.data = mean_sdl, geom = "errorbar") + stat_summary(fun.data = mean_sdl, geom = "errorbar", aes(y = {{y_var}})) +
stat_summary(fun = mean, geom = "point", size = 0.6) stat_summary(fun = mean, geom = "point", size = 0.6, aes(y = {{y_var}}))
} else if (plot_type == "box") { } else if (plot_type == "box") {
plot <- plot + geom_boxplot() plot <- plot + geom_boxplot()
} else if (plot_type == "density") { } else if (plot_type == "density") {
@@ -183,6 +187,7 @@ 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()