Skip to content

Commit

Permalink
Merge pull request satijalab#43 from satijalab/feature/PassDotsPlots
Browse files Browse the repository at this point in the history
Allow passing the dots from VlnPlot/RidgePlot to CombinePlots
  • Loading branch information
andrewwbutler authored Apr 10, 2019
2 parents d9bffe5 + e6b6433 commit c4f69d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
37 changes: 21 additions & 16 deletions R/visualization.R
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ HTOHeatmap <- function(
#' @param ncol Number of columns if multiple plots are displayed
#' @param combine Combine plots into a single gg object; note that if TRUE; themeing will not work when plotting multiple features
#' @param slot Use non-normalized counts data for plotting
#' @param ... Ignored
#' @param ... Extra parameters passed on to \code{\link{CombinePlots}}
#'
#' @return A ggplot object
#'
Expand Down Expand Up @@ -495,7 +495,7 @@ VlnPlot <- function(
slot = 'data',
...
) {
plot <- ExIPlot(
return(ExIPlot(
object = object,
type = 'violin',
features = features,
Expand All @@ -514,8 +514,7 @@ VlnPlot <- function(
slot = slot,
combine = combine,
...
)
return(plot)
))
}

#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -559,8 +558,8 @@ VlnPlot <- function(
#' @param na.value Color value for NA points when using custom scale
#' @param combine Combine plots into a single gg object; note that if TRUE; themeing will not work when plotting multiple features
#' @param ncol Number of columns for display when combining plots
#' @param ... Extra parameters passed on to \code{\link{CombinePlots}}
#'
#' @inheritDotParams CombinePlots
#' @return A ggplot object
#'
#' @importFrom rlang !!
Expand Down Expand Up @@ -1019,18 +1018,18 @@ FeaturePlot <- function(
})
nsplits <- length(x = levels(x = data$split))
idx <- 1
for(i in (length(x = features) * (nsplits - 1) + 1): (length(x = features) * nsplits)) {
for (i in (length(x = features) * (nsplits - 1) + 1):(length(x = features) * nsplits)) {
plots[[i]] <- suppressMessages(plots[[i]] + scale_y_continuous(sec.axis = dup_axis(name = features[[idx]])) + no.right)
idx <- idx + 1
}
idx <- 1
for(i in which(x = 1:length(x = plots) %% length(x = features) == 1)) {
for (i in which(x = 1:length(x = plots) %% length(x = features) == 1)) {
plots[[i]] <- plots[[i]] + ggtitle(levels(x = data$split)[[idx]])
idx <- idx + 1
}
idx <- 1
if (length(x = features) == 1) {
for(i in 1:length(x = plots)) {
for (i in 1:length(x = plots)) {
plots[[i]] <- plots[[i]] + ggtitle(levels(x = data$split)[[idx]])
idx <- idx + 1
}
Expand Down Expand Up @@ -1745,13 +1744,9 @@ DotPlot <- function(
#' @examples
#' ElbowPlot(object = pbmc_small)
#'
ElbowPlot <- function(
object,
ndims = 20,
reduction = 'pca'
) {
ElbowPlot <- function(object, ndims = 20, reduction = 'pca') {
data.use <- Stdev(object = object, reduction = reduction)
if (length(data.use) == 0) {
if (length(x = data.use) == 0) {
stop(paste("No standard deviation info stored for", reduction))
}
if (ndims > length(x = data.use)) {
Expand Down Expand Up @@ -3059,6 +3054,7 @@ Col2Hex <- function(...) {
# @param log plot Y axis on log scale
# @param combine Combine plots using cowplot::plot_grid
# @param slot Use non-normalized counts data for plotting
# @param ... Extra parameters passed to \code{\link{CombinePlots}}
#
#' @importFrom scales hue_pal
#
Expand All @@ -3079,7 +3075,8 @@ ExIPlot <- function(
split.by = NULL,
log = FALSE,
combine = TRUE,
slot = 'data'
slot = 'data',
...
) {
assay <- assay %||% DefaultAssay(object = object)
DefaultAssay(object = object) <- assay
Expand Down Expand Up @@ -3143,7 +3140,15 @@ ExIPlot <- function(
}
)
if (combine) {
plots <- CombinePlots(plots = plots, ncol = ncol, legend = 'none')
combine.args <- list(
'plots' = plots,
'ncol' = ncol
)
combine.args <- c(combine.args, list(...))
if (!'legend' %in% names(x = combine.args)) {
combine.args$legend <- 'none'
}
plots <- do.call(what = 'CombinePlots', args = combine.args)
}
return(plots)
}
Expand Down
2 changes: 2 additions & 0 deletions man/DimPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/RidgePlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/VlnPlot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c4f69d6

Please sign in to comment.