Don't add text aes to static pdf plot

This commit is contained in:
2024-09-12 05:07:16 -04:00
parent 05787bdcbb
commit 9f87b54727

View File

@@ -389,47 +389,52 @@ 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) saveWidget(combined_plot, file = file.path(output_dir, paste0(file_name, ".html")), selfcontained = TRUE)
} }
generate_scatter_plot <- function(plot, config) { generate_scatter_plot <- function(plot, config, interactive = FALSE) {
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), # Determine the base aesthetics
color = as.factor(!!sym(config$color_var)), aes_params <- aes(
text = paste("ORF:", OrfRep, "Gene:", Gene, "delta_bg:", delta_bg)), x = !!sym(config$x_var),
shape = config$shape %||% 3) 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) { } else if (!is.null(config$gene_point) && config$gene_point) {
plot + geom_point(aes(x = !!sym(config$x_var), y = !!sym(config$y_var), aes_params$text <- paste("ORF:", OrfRep, "Gene:", Gene)
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)
} }
# 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$add_smooth) && config$add_smooth) {
if (!is.null(config$lm_line)) { plot <- if (!is.null(config$lm_line)) {
plot <- plot + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope) plot + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope)
} else { } 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)) { if (!is.null(config$x_breaks) && !is.null(config$x_labels) && !is.null(config$x_label)) {
plot <- plot + scale_x_continuous( plot <- plot + scale_x_continuous(
name = config$x_label, name = config$x_label,
breaks = config$x_breaks, breaks = config$x_breaks,
labels = config$x_labels labels = config$x_labels)
)
} }
# Add y-axis limits if specified
if (!is.null(config$ylim_vals)) { if (!is.null(config$ylim_vals)) {
plot <- plot + scale_y_continuous(limits = config$ylim_vals) plot <- plot + scale_y_continuous(limits = config$ylim_vals)
} }
# Add Cartesian coordinates customization if specified
if (!is.null(config$coord_cartesian)) { if (!is.null(config$coord_cartesian)) {
plot <- plot + coord_cartesian(ylim = config$coord_cartesian) plot <- plot + coord_cartesian(ylim = config$coord_cartesian)
} }