scBarplot.CellFractions: Generate Barplot of Cell Fractions

View source: R/Seurat.Utils.Visualization.R

scBarplot.CellFractionsR Documentation

Generate Barplot of Cell Fractions

Description

This function generates a bar plot of cell fractions per cluster from a Seurat object. It offers the option to downsample data, equalizing the number of cells in each group to the number in the smallest group. The plot's bars are grouped by one variable and filled by another. The function supports custom color palettes, drawing numerical values on bars, and saving the plot.

Usage

scBarplot.CellFractions(
  fill.by,
  group.by = GetNamedClusteringRuns()[1],
  obj = combined.obj,
  downsample = FALSE,
  min.nr.sampled.cells = 200,
  plotname = kppws("Cell proportions of", fill.by, "by", group.by),
  suffix = NULL,
  prefix = NULL,
  sub_title = suffix,
  hlines = c(0.25, 0.5, 0.75),
  return_table = FALSE,
  save_table = TRUE,
  save_plot = TRUE,
  also.pdf = FALSE,
  seedNr = 1989,
  draw_plot = TRUE,
  show_numbers = FALSE,
  min.pct = 0.05,
  cex.pct = 2.5,
  min_frequency = 0,
  custom_col_palette = FALSE,
  color_scale = getDiscretePaletteObj(ident.used = fill.by, obj = obj, palette.used =
    "glasbey"),
  rnd_colors = FALSE,
  show.total.cells = TRUE,
  cex.total = 2,
  xlab.angle = 45,
  show_plot = TRUE,
  w = NULL,
  h = 6,
  ...
)

Arguments

fill.by

The variable to fill by for the bar plot.

group.by

The variable to group by for the bar plot.

obj

A Seurat object.

downsample

Logical indicating whether to downsample data to equalize group sizes.

min.nr.sampled.cells

The minimal number of cells to sample from each identity class. Defaults to 200 cells.

plotname

The title of the plot.

suffix

Optional suffix for the plot title.

prefix

Optional prefix for the plot title.

sub_title

Optional subtitle for the plot.

hlines

Numeric vector specifying y-intercepts of horizontal lines to add to the plot.

return_table

Logical; if TRUE, returns a contingency table instead of plotting.

save_table

Logical; if TRUE, saves the table behind the plot.

save_plot

Logical; if TRUE, saves the generated plot.

also.pdf

Save plot in both png and pdf formats.

seedNr

Seed for random number generation to ensure reproducibility.

draw_plot

Logical; if FALSE, suppresses plotting (useful if only the table is desired).

show_numbers

Logical; if TRUE, adds count numbers on top of each bar in the plot.

min.pct

Show % Labels above this threshold. Default = 0.05, or above 5 pct.

cex.pct

Font size of pct labels.

min_frequency

Minimum fraction to display individually in the plot; smaller fractions are aggregated into an "Other" category.

custom_col_palette

Specifies whether to use a standard or custom color palette.

color_scale

Defines the color scale to use for the plot if a custom palette is selected.

show.total.cells

Show total cells

cex.total

Label size for total cells

xlab.angle

Angle of x-axis labels.

show_plot

Logical; if TRUE, shows the plot.

w

Width of the plot in inches. Default: NULL

h

Height of the plot in inches. Default: 6

...

Additional parameters passed to internally called functions.

Value

Depending on the value of return_table, either returns a ggplot object or a list containing values and percentages tables.

See Also

toTitleCase, ggplot, group_by, summarise

Examples

## Not run: 
if (interactive()) {
  scBarplot.CellFractions(obj = combined.obj, group.by = "integrated_snn_res.0.1", fill.by = "Phase", downsample = TRUE)
  scBarplot.CellFractions(obj = combined.obj, group.by = "integrated_snn_res.0.1", fill.by = "Phase", downsample = FALSE)
}

## End(Not run)

vertesy/Seurat.utils documentation built on Dec. 4, 2024, 5:20 p.m.