Use as.factor(conc_num) for plots
This commit is contained in:
@@ -158,13 +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) {
|
||||
# Base ggplot object with conditional y mapping
|
||||
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)))
|
||||
if (!is.null(y_var)) {
|
||||
plot <- ggplot(df, aes(x = !!sym(x_var), y = !!sym(y_var), color = as.factor(!!sym(color_var))))
|
||||
} else {
|
||||
plot <- ggplot(df, aes(x = !!sym(x_var), color = !!sym(color_var)))
|
||||
plot <- ggplot(df, aes(x = !!sym(x_var), color = as.factor(!!sym(color_var))))
|
||||
}
|
||||
|
||||
# Handle different plot types
|
||||
@@ -176,7 +173,7 @@ generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_
|
||||
} else if (plot_type == "box") {
|
||||
plot <- plot + geom_boxplot()
|
||||
} else if (plot_type == "density") {
|
||||
plot <- plot + geom_density() # Density plot automatically maps density to y
|
||||
plot <- plot + geom_density()
|
||||
} else if (plot_type == "bar") {
|
||||
plot <- plot + geom_bar(stat = "identity")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user