knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
suppressMessages({ library(LxCxUtils) library(Seurat) library(SeuratData) })
The LxCxUtils
package mainly uses Seurat objects to get the expression data for the plots, so we first need to setup a Seurat object. We will use the pbmc 3k dataset from the SeuratData
package.
suppressMessages({ data("pbmc3k") pbmc3k })
pbmc3k <- suppressMessages(UpdateSeuratObject(pbmc3k))
pbmc3k <- NormalizeData(pbmc3k, verbose = FALSE) pbmc3k <- FindVariableFeatures(pbmc3k, selection.method = "vst", nfeatures = 2000, verbose = FALSE) pbmc3k <- ScaleData(pbmc3k, verbose = FALSE) pbmc3k <- RunPCA(pbmc3k, verbose = FALSE)
The first visualisation function from LxCxUtils
is the PlotGeneRank
. This function will rank the genes by their expression in each identity of the dataset, and we can even highlight some genes of interest.
#highlight no genes plotGenesRank(pbmc3k, genes_highlight = c()) #highlight some genes plotGenesRank(pbmc3k, genes_highlight = c("FTL", "LYZ", "MALAT1"))
And we can separate the plots by any cluster column from the metadata.
#highlight some genes and separate by clusters plotGenesRank(pbmc3k, genes_highlight = c("FTL", "LYZ", "MALAT1"), group.by = "seurat_annotations")
Another visualization function from the package, which can be used for the QC, is the QC_barplot
. It will plot the distribution of cells along the QC column from the metadata, as an histogram.
#Grouping by default : orig.ident QC_barplot(pbmc3k, features = c("nFeature_RNA"))
We can color the histogram by another column from the metadata
#Coloring by clusters QC_barplot(pbmc3k, features = c("nFeature_RNA"), group.by = "seurat_annotations")
And even separate the histograms, with one for each cluster of this column.
#Coloring and grouping by clusters QC_barplot(pbmc3k, features = c("nFeature_RNA"), group.by = "seurat_annotations", wrap = TRUE)
Another feature of the package is to compute and plot the PCA variance explained. For this we use the function plotVarianceExplained
or plotCumulativeVarExplained
, which respectively plot the variance for each PC, and plot the cumulative variance for each PC, that is adding the variance of all previous PC to each PC.
plotVarianceExplained(pbmc3k) plotCumulativeVarExplained(pbmc3k)
One of the main plotting function from this package is the seuratBoxPlot
, which aims to complement the VlnPlot
from Seurat with a boxplot representation.
#Box plot p1 <- seuratBoxPlot(pbmc3k, "FTL", group.by = "seurat_annotations", pt.size = 0.1) + ggtitle("Boxplot of FTL") # seuratBoxPlot(pbmc3k, "FTL", group.by = "seurat_annotations", pt.size = 0.1) #VlnPlot from Seurat p2 <- VlnPlot(pbmc3k, "FTL", group.by = "seurat_annotations", pt.size = 0.1) + ggtitle("Violin plot of FTL") gridExtra::grid.arrange(p1,p2,ncol = 2)
To choose the best dimension for UMAP, the package has a function that computes all the dimension you ask, and give a plot with the umap for each of these dimensions. This function is called multiUMAP
.
multiUMAP(pbmc3k, dims = 10:20, out = TRUE, save = FALSE, verbose = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.