-
Notifications
You must be signed in to change notification settings - Fork 977
Improves DimHeatmap documentation and default behavior when fast=FALSE (Issue #9810) #9813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,10 +34,11 @@ setGeneric( | |||||||||
| #' @param balanced Plot an equal number of genes with both + and - scores. | ||||||||||
| #' @param projected Use the full projected dimensional reduction | ||||||||||
| #' @param ncol Number of columns to plot | ||||||||||
| #' @param fast If true, use \code{image} to generate plots; faster than using ggplot2, but not customizable | ||||||||||
| #' @param fast If true, use \code{image} to generate plots; faster than using ggplot2, but not customizable and excludes figure legend in output | ||||||||||
| #' @param assays A vector of assays to pull data from | ||||||||||
| #' @param combine Combine plots into a single \code{\link[patchwork]{patchwork}ed} | ||||||||||
| #' @param combine Combine plots into a single \code{\link[patchwork]{patchwork}ed} with single shared figure legend when \code{fast=FALSE} | ||||||||||
| #' ggplot object. If \code{FALSE}, return a list of ggplot objects | ||||||||||
|
Comment on lines
+39
to
40
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| #' @param leg.pos When \code{combine=TRUE}, allows legend position to be adjusted for \code{\link[patchwork]{patchwork}ed} output; defaults as \code{"right"} | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Renaming this parameter to |
||||||||||
| #' | ||||||||||
| #' @return No return value by default. If using fast = FALSE, will return a | ||||||||||
| #' \code{\link[patchwork]{patchwork}ed} ggplot object if combine = TRUE, otherwise | ||||||||||
|
|
@@ -54,21 +55,22 @@ setGeneric( | |||||||||
| #' DimHeatmap(object = pbmc_small) | ||||||||||
| #' | ||||||||||
| DimHeatmap <- function( | ||||||||||
| object, | ||||||||||
| dims = 1, | ||||||||||
| nfeatures = 30, | ||||||||||
| cells = NULL, | ||||||||||
| reduction = 'pca', | ||||||||||
| disp.min = -2.5, | ||||||||||
| disp.max = NULL, | ||||||||||
| balanced = TRUE, | ||||||||||
| projected = FALSE, | ||||||||||
| ncol = NULL, | ||||||||||
| fast = TRUE, | ||||||||||
| raster = TRUE, | ||||||||||
| slot = 'scale.data', | ||||||||||
| assays = NULL, | ||||||||||
| combine = TRUE | ||||||||||
| object, | ||||||||||
| dims = 1, | ||||||||||
| nfeatures = 30, | ||||||||||
| cells = NULL, | ||||||||||
| reduction = 'pca', | ||||||||||
| disp.min = -2.5, | ||||||||||
| disp.max = NULL, | ||||||||||
| balanced = TRUE, | ||||||||||
| projected = FALSE, | ||||||||||
| ncol = NULL, | ||||||||||
| fast = TRUE, | ||||||||||
| raster = TRUE, | ||||||||||
| slot = 'scale.data', | ||||||||||
| assays = NULL, | ||||||||||
| combine = TRUE, | ||||||||||
| leg.pos = "right" | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| ) { | ||||||||||
| ncol <- ncol %||% ifelse(test = length(x = dims) > 2, yes = 3, no = length(x = dims)) | ||||||||||
| plots <- vector(mode = 'list', length = length(x = dims)) | ||||||||||
|
|
@@ -171,14 +173,19 @@ DimHeatmap <- function( | |||||||||
| cell.order = dim.cells, | ||||||||||
| feature.order = dim.features | ||||||||||
| ) | ||||||||||
| plots[[i]] <- plots[[i]] + | ||||||||||
| ggtitle(paste0(Key(object = object[[reduction]]), dims[i])) + | ||||||||||
| theme(plot.title = element_text(hjust = 0.5, face = "bold")) | ||||||||||
| } | ||||||||||
| } | ||||||||||
| if (fast) { | ||||||||||
| par(mfrow = orig.par) | ||||||||||
| return(invisible(x = NULL)) | ||||||||||
| } | ||||||||||
| 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 = leg.pos) | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
| return(plots) | ||||||||||
| } | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function documentation will need to be updated to also import
plot_layout(line 47):#' @importFrom patchwork wrap_plots plot_layoutOtherwise, users will receive an error running DimHeatmap when the patchwork package isn't loaded (Error in plot_layout(guides = "collect") : could not find function "plot_layout").