Skip to content

Improves DimHeatmap documentation and default behavior when fast=FALSE (Issue #9810)#9813

Open
dkcoxie wants to merge 7 commits intosatijalab:mainfrom
dkcoxie:dkcoxie-patch-1
Open

Improves DimHeatmap documentation and default behavior when fast=FALSE (Issue #9810)#9813
dkcoxie wants to merge 7 commits intosatijalab:mainfrom
dkcoxie:dkcoxie-patch-1

Conversation

@dkcoxie
Copy link

@dkcoxie dkcoxie commented Apr 10, 2025

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 #9810

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)
@dkcoxie
Copy link
Author

dkcoxie commented Apr 10, 2025

In preparing teaching materials geared toward beginners, we found that the default behavior of DimHeatmap() either displays no figure legend but includes the PC number as panel titles (default fast=TRUE) OR allows the figure legend to be shown for the ggplot2 output doesn't display the PC number for each panel (when fast=FALSE).

The Proposed changes to theDimHeatmap() function clarify the documentation regarding when a figure legend will be displayed, add PC labels as individual figure titles for the ggplot2 outputs, and allow for the position of the figure legend to be moved when the ggplots are combined into a single patchwork output.

@dkcoxie
Copy link
Author

dkcoxie commented Jul 10, 2025

The related issue was closed so I wanted to check if this improvement to make the output plots more consistent for DimHeatmap() when fast=TRUE and when fast=FALSE in still being considered for the next CRAN release. Thank you!

@anashen
Copy link
Member

anashen commented Sep 11, 2025

Thanks @dkcoxie for your PR & for the follow-up :) Yes, we have added this to the list of PRs to review.

@anashen anashen self-requested a review September 11, 2025 16:44
@anashen anashen changed the base branch from develop to main September 23, 2025 18:16
Copy link
Member

@anashen anashen left a comment

Choose a reason for hiding this comment

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

Thank you @dkcoxie for opening this PR! These changes will definitely be helpful to add. I made a couple of suggestions & would appreciate it if you could take a look.

Copilot AI review requested due to automatic review settings February 19, 2026 17:58
dkcoxie and others added 4 commits February 19, 2026 13:00
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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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=TRUE excludes figure legends from output
  • Added PC number titles (e.g., "PC_1") to each heatmap panel when fast=FALSE with centered, bold formatting
  • Introduced leg.pos parameter 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
@dkcoxie
Copy link
Author

dkcoxie commented Feb 19, 2026

@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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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"}
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

Incorrect grammar in documentation. The phrase "defaults as" should be "defaults to" for grammatically correct documentation.

Suggested change
#' @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"}

Copilot uses AI. Check for mistakes.
#' returns a list of ggplot objects
#'
#' @importFrom patchwork wrap_plots
#' @importFrom patchwork wrap_plots plot_layout
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +186 to +187
plots <- wrap_plots(plots, ncol = ncol, guides = "collect") +
plot_layout(guides = "collect") &
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

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)

Suggested change
plots <- wrap_plots(plots, ncol = ncol, guides = "collect") +
plot_layout(guides = "collect") &
plots <- wrap_plots(plots, ncol = ncol, guides = "collect") &

Copilot uses AI. Check for mistakes.
assays = NULL,
combine = TRUE,
legend.position = "right"
) {
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
) {
) {
# 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
)
}

Copilot uses AI. Check for mistakes.
Comment on lines 185 to +188
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)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@dkcoxie dkcoxie requested a review from anashen February 19, 2026 19:14
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.

Feature Request: Improve DimHeatmap documentation and add PC number title for ggplot2 output

3 participants