Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions R/visualization.R
Copy link
Member

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_layout

Otherwise, 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").

Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#' @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
#' @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 leg.pos When \code{combine=TRUE}, allows legend position to be adjusted for \code{\link[patchwork]{patchwork}ed} output; defaults as \code{"right"}
Copy link
Member

Choose a reason for hiding this comment

The 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"}
#' @param legend.position When \code{combine=TRUE}, allows legend position to be adjusted for \code{\link[patchwork]{patchwork}ed} output; defaults as \code{"right"}

Renaming this parameter to legend.position would make its purpose a bit more clear to users.

#'
#' @return No return value by default. If using fast = FALSE, will return a
#' \code{\link[patchwork]{patchwork}ed} ggplot object if combine = TRUE, otherwise
Expand All @@ -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"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
leg.pos = "right"
legend.position = "right"

) {
ncol <- ncol %||% ifelse(test = length(x = dims) > 2, yes = 3, no = length(x = dims))
plots <- vector(mode = 'list', length = length(x = dims))
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
theme(legend.position = leg.pos)
theme(legend.position = legend.position)

}
return(plots)
}
Expand Down