Skip to content

Commit

Permalink
Returns the ggplot2 objects in the function maaslin_plot_results
Browse files Browse the repository at this point in the history
  • Loading branch information
JTNearing-broad committed Nov 26, 2024
1 parent 98b31a8 commit a9fdd36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions R/maaslin3.R
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,7 @@ maaslin_plot_results <- function(output,
plot_associations = TRUE,
max_pngs = 30,
balanced = FALSE) {
ret_plots <- list()
# create an output folder and figures folder if it does not exist
if (!file.exists(output)) {
logging::loginfo("Creating output folder")
Expand Down Expand Up @@ -2363,7 +2364,7 @@ maaslin_plot_results <- function(output,
heatmap_vars <- trimws(unlist(strsplit(heatmap_vars, ',')))
}

maaslin3_summary_plot(
sum_plot <- maaslin3_summary_plot(
merged_results,
summary_plot_file,
figures_folder,
Expand All @@ -2376,7 +2377,7 @@ maaslin_plot_results <- function(output,
balanced = balanced
)
}

ret_plots[["Summary_plot"]] <- sum_plot
# Individual association plots
if (plot_associations) {
logging::loginfo(
Expand Down Expand Up @@ -2410,9 +2411,9 @@ maaslin_plot_results <- function(output,
invokeRestart("muffleWarning")
})
})

return(plots_out)
ret_plots[["Assocations"]] <- plots_out
}
return(ret_plots)
}

maaslin_plot_results_from_output <- function(output,
Expand Down
5 changes: 5 additions & 0 deletions R/viz.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ maaslin3_summary_plot <-
median_comparison_abundance = FALSE,
median_comparison_prevalence = FALSE,
balanced=FALSE) {
ret_plots <- list()
if (first_n > 200) {
logging::logerror(
paste(
Expand Down Expand Up @@ -686,6 +687,9 @@ maaslin3_summary_plot <-
} else {
final_plot <- NULL
}
ret_plots[["coefficient"]] <- p1
ret_plots[["heat"]] <- p2
ret_plots[["final"]] <- final_plot

# Save plot
if (!is.null(final_plot)) {
Expand Down Expand Up @@ -731,6 +735,7 @@ maaslin3_summary_plot <-
})
})
}
return(ret_plots)
}

# Create a scatterplot for abundance vs. continuous associations
Expand Down

0 comments on commit a9fdd36

Please sign in to comment.