Improves DimHeatmap documentation and default behavior when fast=FALSE (Issue #9810)#9813
Improves DimHeatmap documentation and default behavior when fast=FALSE (Issue #9810)#9813dkcoxie wants to merge 7 commits intosatijalab:mainfrom
Conversation
Clarifies documentation to specify that figure legends are currently not displayed when `fast=TRUE` but added titles with PC numbers to ggplot outputs so that both PC number and figure legends can be displayed on the same plot, plus option to move position of shared patchwork legend when `combine=TRUE` to resolve Issue [satijalab#9810](satijalab#9810)
|
In preparing teaching materials geared toward beginners, we found that the default behavior of The Proposed changes to the |
|
The related issue was closed so I wanted to check if this improvement to make the output plots more consistent for |
|
Thanks @dkcoxie for your PR & for the follow-up :) Yes, we have added this to the list of PRs to review. |
Updated manual message to suggested wording Co-authored-by: Anagha Shenoy <90294056+anashen@users.noreply.github.com>
Updating documentation to reflect change to parameter name for better clarity. Co-authored-by: Anagha Shenoy <90294056+anashen@users.noreply.github.com>
Changing legend parameter name for better clarity. Co-authored-by: Anagha Shenoy <90294056+anashen@users.noreply.github.com>
Changing legend parameter name within function to improve clarity. Co-authored-by: Anagha Shenoy <90294056+anashen@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances the DimHeatmap function to better document its behavior and improve visualization output when using ggplot2 mode (fast=FALSE). The changes address Issue #9810 by adding PC number titles to individual heatmap plots and providing control over legend positioning in combined plots.
Changes:
- Updated documentation to clarify that
fast=TRUEexcludes figure legends from output - Added PC number titles (e.g., "PC_1") to each heatmap panel when
fast=FALSEwith centered, bold formatting - Introduced
leg.posparameter to control legend position in combined patchwork outputs, defaulting to "right"
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Added suggested import to resolve error if patchwork is not already loaded by user
|
@anashen - made the requested changes to my branch for improving the heatmap plotting behavior and documentation. Ignoring the Copilot suggestions since the majority seem to be redundant with the suggestion but happy to make additional changes if needed or change merge destination from main to a development branch. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #' ggplot object. If \code{FALSE}, return a list of ggplot objects | ||
| #' @param combine Combine plots into a single \code{\link[patchwork]{patchwork}ed} ggplot object with | ||
| #' single shared figure legend when \code{fast=FALSE}. If \code{FALSE}, return a list of ggplot objects | ||
| #' @param legend.position When \code{combine=TRUE}, allows legend position to be adjusted for \code{\link[patchwork]{patchwork}ed} output; defaults as \code{"right"} |
There was a problem hiding this comment.
Incorrect grammar in documentation. The phrase "defaults as" should be "defaults to" for grammatically correct documentation.
| #' @param legend.position When \code{combine=TRUE}, allows legend position to be adjusted for \code{\link[patchwork]{patchwork}ed} output; defaults as \code{"right"} | |
| #' @param legend.position When \code{combine=TRUE}, allows legend position to be adjusted for \code{\link[patchwork]{patchwork}ed} output; defaults to \code{"right"} |
| #' returns a list of ggplot objects | ||
| #' | ||
| #' @importFrom patchwork wrap_plots | ||
| #' @importFrom patchwork wrap_plots plot_layout |
There was a problem hiding this comment.
Missing required ggplot2 imports. The code now uses ggtitle, theme, and element_text functions (lines 177-178), but these are not imported in the function documentation. Add ggtitle theme element_text to the importFrom directive to ensure these functions are available.
| plots <- wrap_plots(plots, ncol = ncol, guides = "collect") + | ||
| plot_layout(guides = "collect") & |
There was a problem hiding this comment.
Incorrect patchwork syntax with redundant plot_layout call. The code uses both + and & operators with redundant guides = "collect" specification. When using wrap_plots with guides = "collect", you don't need to add a separate plot_layout(guides = "collect"). The & operator should be used directly after wrap_plots to apply themes to all subplots. Simplify to: plots <- wrap_plots(plots, ncol = ncol, guides = "collect") & theme(legend.position = legend.position)
| plots <- wrap_plots(plots, ncol = ncol, guides = "collect") + | |
| plot_layout(guides = "collect") & | |
| plots <- wrap_plots(plots, ncol = ncol, guides = "collect") & |
| assays = NULL, | ||
| combine = TRUE, | ||
| legend.position = "right" | ||
| ) { |
There was a problem hiding this comment.
Missing input validation for legend.position parameter. The new legend.position parameter accepts any value without validation. Consider adding validation to ensure only valid ggplot2 legend positions are accepted (e.g., "none", "left", "right", "bottom", "top", or a numeric vector of length 2). This would provide better error messages to users who might provide invalid values.
| ) { | |
| ) { | |
| # Validate legend.position to ensure it matches accepted ggplot2 values | |
| if (is.character(legend.position)) { | |
| valid_positions <- c("none", "left", "right", "bottom", "top") | |
| if (length(legend.position) != 1L || !legend.position %in% valid_positions) { | |
| stop( | |
| "legend.position must be one of ", | |
| paste(shQuote(valid_positions), collapse = ", "), | |
| " when supplied as a character string.", | |
| call. = FALSE | |
| ) | |
| } | |
| } else if (is.numeric(legend.position)) { | |
| if (length(legend.position) != 2L) { | |
| stop( | |
| "legend.position must be a numeric vector of length 2 when supplied as numeric.", | |
| call. = FALSE | |
| ) | |
| } | |
| } else { | |
| stop( | |
| "legend.position must be either a character string (\"none\", \"left\", \"right\", \"bottom\", \"top\") ", | |
| "or a numeric vector of length 2.", | |
| call. = FALSE | |
| ) | |
| } |
| if (combine) { | ||
| plots <- wrap_plots(plots, ncol = ncol, guides = "collect") | ||
| plots <- wrap_plots(plots, ncol = ncol, guides = "collect") + | ||
| plot_layout(guides = "collect") & | ||
| theme(legend.position = legend.position) |
There was a problem hiding this comment.
The legend.position parameter only affects the output when combine=TRUE, but this is not checked in the code. When combine=FALSE, the parameter is silently ignored. Consider either: (1) applying the legend position to individual plots in the list when combine=FALSE, or (2) adding a warning when legend.position is specified but combine=FALSE, or (3) clarifying in the documentation that this parameter has no effect when combine=FALSE.
Clarifies documentation to specify that figure legends are currently not displayed when
fast=TRUEbut added titles with PC numbers to ggplot outputs so that both PC number and figure legends can be displayed on the same plot, plus option to move position of shared patchwork legend whencombine=TRUEto resolve Issue #9810