Skip to content

Enhance plotting functions and documentation#8

Open
AbhirupaGhosh wants to merge 10 commits into
mainfrom
plotting_ml_results
Open

Enhance plotting functions and documentation#8
AbhirupaGhosh wants to merge 10 commits into
mainfrom
plotting_ml_results

Conversation

@AbhirupaGhosh

Copy link
Copy Markdown
Contributor

Updated documentation for plotPRC, plotROC, plotCM, plotDensity, and plotTopFeatsVI functions. Added new functions for plotting ROC curves, confusion matrices, and density of predicted class probabilities.

Description

What kind of change(s) are included?

  • Feature (adds or updates new capabilities)
  • Bug fix (fixes an issue).
  • Enhancement (adds functionality).
  • Breaking change (these changes would cause existing functionality to not work as expected).

Checklist

Please ensure that all boxes are checked before indicating that this pull request is ready for review.

  • I have read and followed the CONTRIBUTING.md guidelines.
  • I have searched for existing content to ensure this is not a duplicate.
  • I have performed a self-review of these additions (including spelling, grammar, and related).
  • I have added comments to my code to help provide understanding.
  • I have added a test which covers the code changes found within this PR.
  • I have deleted all non-relevant text in this pull request template.
  • Reviewer assignment: Tag a relevant team member to review and approve the changes.

Updated documentation for plotPRC, plotROC, plotCM, plotDensity, and plotTopFeatsVI functions. Added new functions for plotting ROC curves, confusion matrices, and density of predicted class probabilities.
epbrenner
epbrenner previously approved these changes Jan 20, 2026

@epbrenner epbrenner left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These work, but I'd strongly suggest that the import functions for the plots to natively include the tsv reading rather than requiring it.

@AbhirupaGhosh AbhirupaGhosh marked this pull request as draft May 29, 2026 22:25
@AbhirupaGhosh AbhirupaGhosh requested review from amcim and eboyer221 June 2, 2026 14:00
@AbhirupaGhosh

Copy link
Copy Markdown
Contributor Author

These work, but I'd strongly suggest that the import functions for the plots to natively include the tsv reading rather than requiring it.

I have modified the function to input tsv.
I have added additional plotting functions based on my Staph poster and a few others. @eboyer221, please look through the plots to decide if anything can be adapted for the dashboard or generate an Rmd as the end product of amRml.

@AbhirupaGhosh AbhirupaGhosh marked this pull request as ready for review June 2, 2026 14:03
@eboyer221

Copy link
Copy Markdown
Contributor

@AbhirupaGhosh @jananiravi @amcim
I am currently reviewing these plots and working on adding them into the amRviz dashboard, along with an option to export them. Since plotCrossDrug() uses ComplexHeatmap, bringing that into amRviz will give us a Bioconductor dependency we need, which should help resolve the BiocCheck warning we have been hitting in that package.

Comment thread R/plot_ml.R
#' @return A heatmap (`ggplot2` object) showing the confusion matrix.
#'
#' @export
plotCM <- function(test_data_plus_predictions_file) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plotConfusion will seem odd?

Comment thread R/plot_ml.R
#' @param shuffled_label_results Output of `runMLPipeline(shuffle_labels = TRUE)`
#'
#' @importFrom graphics barplot
#' @return A base R barplot comparing balanced accuracy across models.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why base R?

Comment thread R/plot_ml.R
beside = TRUE,
legend.text = TRUE, col = c("skyblue", "lightpink"),
ylab = "Balanced accuracy", xlab = "Antibiotic"
ylab = "Balanced Accuracy"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ylab = "Balanced Accuracy"
ylab = "Balanced accuracy"

Comment thread R/plot_ml.R
"#0F2A5A" # very dark for ~1
),
values = scales::rescale(c(-1, 0, 0.85, 1)),
name = "Best MCC"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AbhirupaGhosh including ties?

Comment thread R/plot_ml.R
Comment on lines +478 to +485
feat_pal <- c(
"args" = "#56B4E9", # sky blue
"cogs" = "#E69F00", # orange
"genes" = "#009E73", # bluish green
"domains" = "#F0E442", # yellow
"proteins" = "#CC79A7", # reddish purple
"struct" = "#D55E00" # vermillion
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not defined separately in a function -- so it's the same colors across plots/panels?

Comment thread R/plot_ml.R
final_plot
}

#' Plot cross-drug generalization heatmap

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless I'm missing something

Suggested change
#' Plot cross-drug generalization heatmap
#' Plot cross-drug prediction as a heatmap

Comment thread R/plot_ml.R
cross_drug <- arrow::read_parquet(file.path(cross_test_performance_path, "cross_drug_perf.parquet"))
performance <- arrow::read_parquet(file.path(drug_performance_path, "all_performance.parquet"))

###################### CROSS DRUG Testing #############################

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
###################### CROSS DRUG Testing #############################

Comment thread R/plot_ml.R
tibble::column_to_rownames("drug_or_class") |>
as.matrix()

row_order <- heatmap_df |>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drugs ordered by their classes?

Comment thread R/plot_ml.R
Comment on lines +784 to +788
ggplot2::labs(
title = if (year_or_country == "year") {
"Temporal performance by drug"
} else {
"Geographical performance by drug"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ggplot2::labs(
title = if (year_or_country == "year") {
"Temporal performance by drug"
} else {
"Geographical performance by drug"
ggplot2::labs(
title = if (year_or_country == "year") {
"Performance of AMR drug models with temporal holdouts"
} else {
"Performance of AMR drug models with geographical holdouts"

Comment thread R/plot_ml.R
#' )
plotTopClusters <- function(top_feat_path = ".", cluster_feature_path = ".",
protein_names_path = ".", top_n = 10) {
################### Top features #########################

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
################### Top features #########################

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants