Return plot config separately

This commit is contained in:
2024-09-14 23:11:01 -04:00
parent 0bb07cf643
commit d79f6a4f2c

View File

@@ -418,17 +418,18 @@ generate_and_save_plots <- function(output_dir, file_name, plot_configs, grid_la
plot # default case if no type matches plot # default case if no type matches
) )
return(plot) return(list(plot = plot, config = config))
}) })
# PDF saving logic # PDF saving logic
pdf(file.path(output_dir, paste0(file_name, ".pdf")), width = 14, height = 9) pdf(file.path(output_dir, paste0(file_name, ".pdf")), width = 14, height = 9)
lapply(plots, print) lapply(plots, function(item) print(item$plot))
dev.off() dev.off()
# HTML saving logic # HTML saving logic
plotly_plots <- lapply(plots, function(plot) { plotly_plots <- lapply(plots, function(item) {
config <- plot$config plot <- item$plot
config <- item$config
if (!is.null(config$legend_position) && config$legend_position == "bottom") { if (!is.null(config$legend_position) && config$legend_position == "bottom") {
suppressWarnings(ggplotly(plot, tooltip = "text") %>% layout(legend = list(orientation = "h"))) suppressWarnings(ggplotly(plot, tooltip = "text") %>% layout(legend = list(orientation = "h")))
} else { } else {
@@ -605,6 +606,7 @@ generate_interaction_plot_configs <- function(df, variables) {
) )
annotations <- lapply(names(annotation_positions[[variable]]), function(annotation_name) { annotations <- lapply(names(annotation_positions[[variable]]), function(annotation_name) {
message("Processing annotation: ", annotation_name, " for variable: ", variable)
y_pos <- annotation_positions[[variable]][[annotation_name]] y_pos <- annotation_positions[[variable]][[annotation_name]]
# Check if the annotation_name exists in annotation_labels # Check if the annotation_name exists in annotation_labels