knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(dplyr)
library(scmisc)

set.seed(1)

Installation

You can install the release version of scmisc from Github with:

remotes::install_github("ddiez/scmisc")

Toy dataset

This toy dataset contains 493 cells from mice in a SingleCellExperiment object.

sce

We can create some grouping variables.

sce$group1 <- sample(c("A", "B"), ncol(sce), replace = TRUE)
sce$group2 <- sample(c("C", "D"), ncol(sce), replace = TRUE)

Preprocess

To calculate PCA we can use reduce_dim.

sce <- reduce_dim(sce, method = "pca")

Plots

There are several plotting functions that work with Seurat and SingleCellExperiment objects.

Scatter plot

plot_coord(sce)
plot_coord(sce, color = "group1")
plot_coord(sce, color = "group2")

Expand by grouping variable.

plot_coord(sce, expand = "group1")

plot_coord(sce, expand = c("group1", "group2"))

Heatmap

The function plot_heatmap is a wrapper around ComplexHeatmap::Heatmap that simplifies plotting SingleCellExperiment and Seurat objects.

plot_heatmap(sce[1:20, ])

We can use ComplexHeatmap advance annotation features with the heatmap by passing them directly.

cols <- circlize::colorRamp2(c(-2, 0, 2), c("purple", "black", "yellow"))
plot_heatmap(sce[1:20, ], col = cols)
plot_heatmap(sce[1:20, ], column_split = sce$group1)

For column annotations we can directly pass the variable names to use with the color specification using top_ann and top_ann_col.

col <- list(group1 = c(A = "lightgrey", B = "black"),
            group2 = c("C" = "limegreen", "D" = "violetred"))
plot_heatmap(sce[1:20, ], column_split = sce$group1, top_ann = c("group1", "group2"), top_ann_col = col)


ddiez/scmisc documentation built on July 21, 2024, 11:35 a.m.