Don't add text aes to static pdf plot
This commit is contained in:
@@ -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)
|
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),
|
||||||
} else if (!is.null(config$gene_point) && config$gene_point) {
|
color = as.factor(!!sym(config$color_var)))
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is.null(config$add_smooth) && config$add_smooth) {
|
# Add the interactive `text` aesthetic if `interactive` is TRUE
|
||||||
if (!is.null(config$lm_line)) {
|
if (interactive) {
|
||||||
plot <- plot + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope)
|
if (!is.null(config$delta_bg_point) && config$delta_bg_point) {
|
||||||
} else {
|
aes_params$text <- paste("ORF:", OrfRep, "Gene:", Gene, "delta_bg:", delta_bg)
|
||||||
plot <- plot + geom_smooth(method = "lm", se = FALSE)
|
} 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) {
|
||||||
|
plot <- if (!is.null(config$lm_line)) {
|
||||||
|
plot + geom_abline(intercept = config$lm_line$intercept, slope = config$lm_line$slope)
|
||||||
|
} else {
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
return(plot)
|
return(plot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user