Adding EnhancedVolcano function to the package#87
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Volcano_Plot() function to generate static + interactive volcano plots (via EnhancedVolcano + plotly) and adds a testthat unit test suite using synthetic DEG data.
Changes:
- Added
R/Volcano_Plot.Rimplementing volcano plot generation for one or multiple comparisons, returning plots plus ranked output data. - Added
tests/testthat/test-Volcano_Plot.Rcovering basic execution, return structure, multiple comparisons, and a few edge cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
R/Volcano_Plot.R |
New exported plotting function using EnhancedVolcano with optional labeling and interactive plotly output. |
tests/testthat/test-Volcano_Plot.R |
New tests validating Volcano_Plot() output structure and a few edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #' @import ggplot2 | ||
| #' @import dplyr | ||
| #' @import tidyr | ||
| #' @importFrom stringr str_split | ||
| #' @importFrom ggrepel geom_text_repel | ||
| #' @importFrom EnhancedVolcano EnhancedVolcano | ||
| #' @importFrom plotly ggplotly | ||
| #' @importFrom grid grid.newpage | ||
| #' @export |
There was a problem hiding this comment.
This function imports and calls EnhancedVolcano::EnhancedVolcano, but the package is not listed in DESCRIPTION (so R CMD check will fail once NAMESPACE is regenerated). Add EnhancedVolcano to Imports (or Suggests + guard usage), and ensure NAMESPACE/man/ are regenerated to include the new @export and imports.
| # Extract the data used for plotting | ||
| plot_data <- ggplot_build(p_empty)$data[[1]] | ||
|
|
||
| pxx <- p_empty + | ||
| xlab("Fold Change") + | ||
| ylab("Significance") + | ||
| theme_minimal() + | ||
| geom_point(aes( | ||
| text = paste("Gene:", df[[label.col]], | ||
| "<br>Log2FC:", df[[lfc_name]], | ||
| "<br>P-value:", df[[sig_name]]), | ||
| colour = as.character(plot_data$colour), | ||
| fill = as.character(plot_data$colour) | ||
| ), | ||
| shape = 21, | ||
| size = 2, | ||
| stroke = 0.1) + | ||
| scale_fill_identity() |
There was a problem hiding this comment.
The interactive plot construction adds a new geom_point() layer on top of p_empty, so points are drawn twice (once from EnhancedVolcano, once from the added layer) and pointSize/other aesthetics may diverge between layers. Consider attaching the text aesthetic to the existing point layer (or modifying/replacing that layer) so the interactive plot doesn’t duplicate geometry and avoids the extra ggplot_build() work.
| # Extract the data used for plotting | |
| plot_data <- ggplot_build(p_empty)$data[[1]] | |
| pxx <- p_empty + | |
| xlab("Fold Change") + | |
| ylab("Significance") + | |
| theme_minimal() + | |
| geom_point(aes( | |
| text = paste("Gene:", df[[label.col]], | |
| "<br>Log2FC:", df[[lfc_name]], | |
| "<br>P-value:", df[[sig_name]]), | |
| colour = as.character(plot_data$colour), | |
| fill = as.character(plot_data$colour) | |
| ), | |
| shape = 21, | |
| size = 2, | |
| stroke = 0.1) + | |
| scale_fill_identity() | |
| # Add hover text aesthetic directly to the existing plot | |
| pxx <- p_empty + | |
| xlab("Fold Change") + | |
| ylab("Significance") + | |
| theme_minimal() + | |
| aes( | |
| text = paste( | |
| "Gene:", df[[label.col]], | |
| "<br>Log2FC:", df[[lfc_name]], | |
| "<br>P-value:", df[[sig_name]] | |
| ) | |
| ) |
There was a problem hiding this comment.
I need more time to check this suggestion, skipping for now
Putting extra check for empty labels ("Fold change", "Significance")
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removing library call for dplyr in test Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
A quick description: Enhanced Volcano is now a function into the R folder and created a unit test with synthetic data