plotCellTypeProps: Plot cell type proportions for each sample

View source: R/plotCellTypeProps.R

plotCellTypePropsR Documentation

Plot cell type proportions for each sample

Description

This is a plotting function that shows the cell type composition for each sample as a stacked barplot. The plotCellTypeProps returns a ggplot2 object enabling the user to make style changes as required.

Usage

plotCellTypeProps(x = NULL, clusters = NULL, sample = NULL)

Arguments

x

object of class SingleCellExperiment or Seurat

clusters

a factor specifying the cluster or cell type for every cell. For SingleCellExperiment objects this should correspond to a column called clusters in the colData assay. For Seurat objects this will be extracted by a call to Idents(x).

sample

a factor specifying the biological replicate for each cell. For SingleCellExperiment objects this should correspond to a column called sample in the colData assay and for Seurat objects this should correspond to x$sample.

Value

a ggplot2 object

Author(s)

Belinda Phipson

Examples


library(speckle)
library(ggplot2)
library(limma)

# Generate some fake data from a multinomial distribution
# Group A, 4 samples, 1000 cells in each sample
countsA <- rmultinom(4, size=1000, prob=c(0.1,0.3,0.6))
colnames(countsA) <- paste("s",1:4,sep="")

# Group B, 3 samples, 800 cells in each sample

countsB <- rmultinom(3, size=800, prob=c(0.2,0.05,0.75))
colnames(countsB) <- paste("s",5:7,sep="")
rownames(countsA) <- rownames(countsB) <- paste("c",0:2,sep="")

allcounts <- cbind(countsA, countsB)
sample <- c(rep(colnames(allcounts),allcounts[1,]),
          rep(colnames(allcounts),allcounts[2,]),
          rep(colnames(allcounts),allcounts[3,]))
clust <- rep(rownames(allcounts),rowSums(allcounts))

plotCellTypeProps(clusters=clust, sample=sample)


Oshlack/speckle documentation built on Oct. 16, 2022, 9:39 a.m.