|
@@ -389,51 +389,56 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
|
|
|
saveWidget(combined_plot, file = file.path(output_dir, paste0(file_name, ".html")), selfcontained = TRUE)
|
|
|
}
|
|
|
|
|
|
-generate_scatter_plot <- function(plot, config) {
|
|
|
- plot <- if (!is.null(config$delta_bg_point) && config$delta_bg_point) {
|
|
|
- plot + geom_point(aes(x = !!sym(config$x_var), y = !!sym(config$y_var),
|
|
|
- color = as.factor(!!sym(config$color_var)),
|
|
|
- text = paste("ORF:", OrfRep, "Gene:", Gene, "delta_bg:", delta_bg)),
|
|
|
- shape = config$shape %||% 3)
|
|
|
- } else if (!is.null(config$gene_point) && config$gene_point) {
|
|
|
- plot + geom_point(aes(x = !!sym(config$x_var), y = !!sym(config$y_var),
|
|
|
- color = as.factor(!!sym(config$color_var)),
|
|
|
- text = paste("ORF:", OrfRep, "Gene:", Gene)),
|
|
|
- shape = config$shape %||% 3, position = "jitter")
|
|
|
- } else if (!is.null(config$position) && config$position == "jitter") {
|
|
|
- plot + geom_point(aes(x = !!sym(config$x_var), y = !!sym(config$y_var),
|
|
|
- color = as.factor(!!sym(config$color_var))),
|
|
|
- shape = config$shape %||% 3, size = config$size %||% 0.2, position = "jitter")
|
|
|
- } else {
|
|
|
- plot + geom_point(aes(x = !!sym(config$x_var), y = !!sym(config$y_var),
|
|
|
- color = as.factor(!!sym(config$color_var))),
|
|
|
- shape = config$shape %||% 3, size = config$size %||% 0.2)
|
|
|
+generate_scatter_plot <- function(plot, config, interactive = FALSE) {
|
|
|
+
|
|
|
+ # Determine the base aesthetics
|
|
|
+ aes_params <- aes(
|
|
|
+ x = !!sym(config$x_var),
|
|
|
+ y = !!sym(config$y_var),
|
|
|
+ color = as.factor(!!sym(config$color_var)))
|
|
|
+
|
|
|
+ # Add the interactive `text` aesthetic if `interactive` is TRUE
|
|
|
+ if (interactive) {
|
|
|
+ if (!is.null(config$delta_bg_point) && config$delta_bg_point) {
|
|
|
+ aes_params$text <- paste("ORF:", OrfRep, "Gene:", Gene, "delta_bg:", delta_bg)
|
|
|
+ } else if (!is.null(config$gene_point) && config$gene_point) {
|
|
|
+ aes_params$text <- paste("ORF:", OrfRep, "Gene:", Gene)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ # Add the base geom_point layer
|
|
|
+ plot <- plot + geom_point(
|
|
|
+ aes_params, shape = config$shape %||% 3,
|
|
|
+ size = config$size %||% 0.2,
|
|
|
+ position = if (!is.null(config$position) && config$position == "jitter") "jitter" else "identity")
|
|
|
+
|
|
|
+ # Add smooth line if specified
|
|
|
if (!is.null(config$add_smooth) && config$add_smooth) {
|
|
|
- if (!is.null(config$lm_line)) {
|
|
|
- plot <- plot + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope)
|
|
|
+ plot <- if (!is.null(config$lm_line)) {
|
|
|
+ plot + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope)
|
|
|
} else {
|
|
|
- plot <- plot + geom_smooth(method = "lm", se = FALSE)
|
|
|
+ plot + geom_smooth(method = "lm", se = FALSE)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ # Add x-axis customization if specified
|
|
|
if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
|
|
|
plot <- plot + scale_x_continuous(
|
|
|
name = config$x_label,
|
|
|
breaks = config$x_breaks,
|
|
|
- labels = config$x_labels
|
|
|
- )
|
|
|
+ labels = config$x_labels)
|
|
|
}
|
|
|
|
|
|
+ # Add y-axis limits if specified
|
|
|
if (!is.null(config$ylim_vals)) {
|
|
|
plot <- plot + scale_y_continuous(limits = config$ylim_vals)
|
|
|
}
|
|
|
|
|
|
+ # Add Cartesian coordinates customization if specified
|
|
|
if (!is.null(config$coord_cartesian)) {
|
|
|
plot <- plot + coord_cartesian(ylim = config$coord_cartesian)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return(plot)
|
|
|
}
|
|
|
|