Skip to content

Commit

Permalink
Add vertical spacing control StackedVlnPlot
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-marsh committed Nov 18, 2021
1 parent ebce6e2 commit d3d7932
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions R/Plotting_Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ PC_Plotting <- function(
#' @noRd
#'
#' @author Ming Tang (Original Code), Sam Marsh (Modified function for use in scCustomtize)
#' @references https://divingintogeneticsandgenomics.rbind.io/post/stacked-violin-plot-for-visualizing-single-cell-data-in-seurat/
#' @references https://divingintogeneticsandgenomics.rbind.io/post/stacked-violin-plot-for-visualizing-single-cell-data-in-seurat/. Solution for re-enabling plot spacing modification by Abdenour ABBAS (comment on original blog post; http://disq.us/p/2b54qh2).
#' @seealso https://twitter.com/tangming2005
#'

Expand All @@ -76,7 +76,7 @@ Modify_VlnPlot <- function(
features,
pt.size = 0,
cols = NULL,
plot_margin = unit(c(-0.5, 0, -0.5, 0), "cm"),
plot_margin = NULL,
...
) {
#remove the x-axis text and tick
Expand Down
11 changes: 10 additions & 1 deletion R/Seurat_Plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,14 @@ Meta_Highlight_Plot <- function(
#' groups plotted is greater than 36. Default = 123.
#' @param ggplot_default_colors logical. If `colors_use = NULL`, Whether or not to return plot using
#' default ggplot2 "hue" palette instead of default "polychrome" or "varibow" palettes.
#' @param plot_spacing Numerical value specifying the vertical spacing between each plot in the stack.
#' Default is 0.15 ("cm"). Spacing dependent on unit provided to `spacing_unit`.
#' @param spacing_unit Unit to use in specifying vertical spacing between plots. Default is "cm".
#' @param ... Extra parameters passed to \code{\link[Seurat]{VlnPlot}}.
#'
#' @return A ggplot object
#'
#' @import ggplot2
#' @import patchwork
#' @importFrom purrr map map_dbl map2
#' @importFrom Seurat VlnPlot
Expand Down Expand Up @@ -674,6 +678,8 @@ Stacked_VlnPlot <- function(
colors_use = NULL,
color_seed = 123,
ggplot_default_colors = FALSE,
plot_spacing = 0.15,
spacing_unit = "cm",
...
) {
# Check Seurat
Expand Down Expand Up @@ -722,8 +728,11 @@ Stacked_VlnPlot <- function(
}
}

# Setup plot spacing/margin parameter
plot_margin <- margin(t = plot_spacing, r = 0, b = plot_spacing, l = 0, unit = spacing_unit)

# Create plots
plot_list <- map(all_found_features, function(x) Modify_VlnPlot(seurat_object = seurat_object, features = x, cols = colors_use, group.by = group.by, split.by = split.by, idents = idents, ...))
plot_list <- map(all_found_features, function(x) Modify_VlnPlot(seurat_object = seurat_object, features = x, cols = colors_use, group.by = group.by, split.by = split.by, idents = idents, plot_margin = plot_margin, ...))

# Add back x-axis title to bottom plot. patchwork is going to support this?
# Add ability to rotate the X axis labels to the function call
Expand Down

0 comments on commit d3d7932

Please sign in to comment.