Add horizontal legend support to plotly
This commit is contained in:
@@ -61,7 +61,6 @@ args <- parse_arguments()
|
||||
dir.create(file.path(args$out_dir, "zscores"), showWarnings = FALSE)
|
||||
dir.create(file.path(args$out_dir, "zscores", "qc"), showWarnings = FALSE)
|
||||
|
||||
# Define themes and scales
|
||||
# Define themes and scales
|
||||
theme_publication <- function(base_size = 14, base_family = "sans", legend_position = "bottom") {
|
||||
theme_foundation <- ggplot2::theme_grey(base_size = base_size, base_family = base_family)
|
||||
@@ -175,7 +174,11 @@ generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_
|
||||
} else if (plot_type == "density") {
|
||||
plot <- plot + geom_density()
|
||||
} else if (plot_type == "bar") {
|
||||
plot <- plot + geom_bar(stat = "identity")
|
||||
if (!is.null(y_var)) {
|
||||
plot <- plot + geom_bar(stat = "identity") # Use y aesthetic if provided
|
||||
} else {
|
||||
plot <- plot + geom_bar() # Default to counting occurrences
|
||||
}
|
||||
}
|
||||
|
||||
# Add titles and labels
|
||||
@@ -188,6 +191,7 @@ generate_plot <- function(df, x_var, y_var = NULL, plot_type, color_var = "conc_
|
||||
return(plot)
|
||||
}
|
||||
|
||||
|
||||
generate_and_save_plots <- function(df, output_dir, prefix, variables, include_qc = FALSE) {
|
||||
plots <- list()
|
||||
|
||||
@@ -264,16 +268,20 @@ save_plots <- function(file_name, plot_list, output_dir) {
|
||||
})
|
||||
dev.off()
|
||||
|
||||
# Save to HTML
|
||||
# Save to HTML with horizontal legend orientation
|
||||
lapply(names(plot_list), function(plot_name) {
|
||||
pgg <- suppressWarnings(ggplotly(plot_list[[plot_name]]) %>%
|
||||
layout(legend = list(orientation = "h")))
|
||||
|
||||
saveWidget(
|
||||
ggplotly(plot_list[[plot_name]]),
|
||||
pgg,
|
||||
file = file.path(output_dir,
|
||||
paste0(file_name, "_", plot_name, ".html")),
|
||||
selfcontained = TRUE)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
# Calculate background strain mean values
|
||||
calculate_background_means <- function(df_stats_by_l, df_stats_by_k, df_stats_by_r, df_stats_by_auc) {
|
||||
list(
|
||||
|
||||
Reference in New Issue
Block a user