More axes scaling support

This commit is contained in:
2024-09-12 02:55:59 -04:00
parent 626beec271
commit 44da325de4

View File

@@ -377,13 +377,26 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
}
}
if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label) && config$plot_type != "box") {
plot <- plot + scale_x_continuous(
name = config$x_label,
breaks = config$x_breaks,
labels = config$x_labels
)
}
if (!is.null(config$ylim_vals)) {
plot <- plot + scale_y_continuous(limits = config$ylim_vals)
}
if (!is.null(config$delta_bg_point) && config$delta_bg_point) {
plot <- plot +
geom_errorbar(aes(
ymin = !!sym(paste0("mean_", config$y_var)) - !!sym(paste0("sd_", config$y_var)),
ymax = !!sym(paste0("mean_", config$y_var)) + !!sym(paste0("sd_", config$y_var))),
width = 0.1) +
geom_point(aes(y = !!sym(paste0("mean_", config$y_var))), size = 0.6)
}
plot
},
@@ -414,24 +427,18 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope, color = "tomato3") +
annotate("text", x = 0, y = 0, label = config$correlation_text),
"box" = plot + geom_boxplot(),
"density" = plot + geom_density(),
"bar" = plot + geom_bar()
)
# Conditionally apply scale_x_continuous if x_breaks, x_labels, and x_label are present
if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
plot <- plot + scale_x_continuous(
"box" = {
plot <- plot + geom_boxplot()
if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label) && config$plot_type == "box") {
plot <- plot + scale_x_discrete(
name = config$x_label,
breaks = config$x_breaks,
labels = config$x_labels
)
}
# Conditionally apply scale_y_continuous if ylim_vals is present
if (!is.null(config$ylim_vals)) {
plot <- plot + scale_y_continuous(limits = config$ylim_vals)
}
}},
"density" = plot + geom_density(),
"bar" = plot + geom_bar()
)
plot
})