Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

和降维图保持一致的细胞类群统计图 #4173

Closed
ixxmu opened this issue Nov 30, 2023 · 1 comment
Closed

和降维图保持一致的细胞类群统计图 #4173

ixxmu opened this issue Nov 30, 2023 · 1 comment

Comments

@ixxmu
Copy link
Owner

ixxmu commented Nov 30, 2023

https://mp.weixin.qq.com/s/PRStNRokP3oCgGStbiNRLw

@ixxmu
Copy link
Owner Author

ixxmu commented Nov 30, 2023

和降维图保持一致的细胞类群统计图 by YuLabSMU

首先来个Seurat的套路代码:

library(Seurat)
dir = "data/filtered_gene_bc_matrices/hg19"

pbmc.data <- Read10X(data.dir = dir)
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k"
                          min.cells=3, min.features=200)
pbmc[["percent.mt"]] <- PercentageFeatureSet(pbmc, pattern = "^MT-")
pbmc <- subset(pbmc,
  subset = nFeature_RNA > 200 & nFeature_RNA < 2500 & percent.mt < 5
)

pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize",
                      scale.factor = 10000)
pbmc <- ScaleData(pbmc)

pbmc <- FindVariableFeatures(pbmc, selection.method = "vst",
                             nfeatures = 2000)
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
pbmc <- RunUMAP(pbmc, dims = 1:10)

pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)

## Assigning cell type identity to clusters
cluster.ids <- c("Naive CD4 T""CD14+ Mono""Memory CD4 T"
            "B""CD8 T""FCGR3A+ Mono""NK""DC""Platelet")
names(cluster.ids) <- levels(pbmc)
pbmc <- RenameIdents(pbmc, cluster.ids)

再来画个降维图:

library(ggplot2)
library(ggsc)

p <- sc_dim(pbmc) + sc_dim_geom_label()
p

如果你想可视化不同类别的细胞数目,是不是还稍微有点麻烦,统计一下,画个柱状图,这个一点都不麻烦,麻烦的是你要和你的降维图保持颜色对应。所以有一些解决方案,是写个函数,同时把两个图都出了,画在一起。但这样子绑死呢,就会降低灵活性。我的一向思路是保持最简单,然后可组合。那么在ggsc我们是怎么做的?那就是你画你的降维图,然后拿降维图来做为输入,画柱状图,让柱状图和降维图保持一致。

一条指令出图:

sc_dim_count(p)

假设我换个配色方案,柱状图跟着变:

p <- p + scale_color_viridis_d()
p2 <- sc_dim_count(p)
aplot::plot_list(p, p2, widths=c(1.5))

另外如果你是用Seurat画的图,也是可以支持的。

p3 <- DimPlot(pbmc, reduction = "umap",
          label = TRUE, pt.size = 0.5
p4 <- sc_dim_count(p3)
aplot::plot_list(p3, p4, widths=c(1.5))

KISS(Keep It Simple and Stupid)原则是我们所追求的。

@ixxmu ixxmu changed the title archive_request 和降维图保持一致的细胞类群统计图 Nov 30, 2023
@ixxmu ixxmu closed this as completed Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant